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条)

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?