douzouchang7448 2014-07-22 10:50
浏览 78
已采纳

单击后使用php获取按钮的ID

I have 4 buttons,and also an exportexcel button.I want to set the excel filename.If i clicked getToday button, i want to set the today date to the excel.

<div class="span3 btns_state">
    <div data-toggle="buttons-radio" id="toggleButton" class="btn-group clearfix sepH_a">
        <button type="button" name="getTday" id="getToday" class="btn btn-info rep_data tip-bottom active" data-original-title="<?php echo $today;?>"onclick = "show()">Today</button>
        <button type="button" name="getWeek" id="getWeek" class="btn btn-info rep_data tip-bottom" data-original-title="<?php echo $this_week;?>"onclick = "show()">This Week</button>
        <button type="button" name="getMonth" id="getMonth" class="btn btn-info rep_data tip-bottom" data-original-title="<?php echo $this_month;?>"onclick = "show()">This Month</button>
        <button type="button" name="getPreMonth" id="getpremon"class="btn btn-info rep_data tip-bottom" data-original-title="<?php echo $previous_month;?>"onclick = "show()">Last Month</button>
    </div>
</div>

My php code to get the dates.

 $str = $_GET['getTday'];
 if($str == 'getToday')
 {
   $var=$today; 
 }
 else
 {
   $var=$this_week;
 }

I want to retrieve the dates corresponding to the button i clicked,but only else part is working. Here is the excel export.

saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), Report-<?php echo $var?>.xlsx");
  • 写回答

4条回答 默认 最新

  • dp7311 2014-07-22 11:45
    关注

    You can use query string to pass the value of clicked button

    refer the "Today" button below.

    You can set the value of variable "$var" to your execel or anything.

    [Note:I done in the same page,create "test.php" and paste the following code and try,it will works well]

    Thank You.

    <?php 
     //Assume Variables $today and $this_week like below
     $today = date('Y-m-d');
     $this_week = "This week";
     $var = "";
     if(isset($_GET['getTday'])):
     $str = $_GET['getTday'];
        if($str == 'getToday')
        {
          $var=$today; 
        }
        else
        {
         $var=$this_week;
        }
    
     endif;
     echo $var;
    ?>
    <div class="span3 btns_state">
            <div data-toggle="buttons-radio" id="toggleButton" class="btn-group clearfix sepH_a"  >
                <button type="button" name="getTday" id="getToday" class="btn btn-info rep_data tip-bottom active" data-original-title="<?php echo $today;?>"onclick = "show('getToday')">Today</button>
                <button type="button" name="getWeek" id="getWeek" class="btn btn-info rep_data tip-bottom" data-original-title="<?php echo $this_week;?>"onclick = "show()">This Week</button>
                <button type="button" name="getMonth" id="getMonth" class="btn btn-info rep_data tip-bottom" data-original-title="<?php echo $this_month;?>"onclick = "show()">This Month</button>
                <button type="button" name="getPreMonth" id="getpremon"class="btn btn-info rep_data tip-bottom" data-original-title="<?php echo $previous_month;?>"onclick = "show()">Last Month</button>
    
            </div>
          </div>
    <script>
    function show(val)
    {
    if(val == 'getToday')
    {
        location.href = "test.php?getTday=getToday";
    }
    }
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?