单击后使用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");

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>

Using jquery click event to perform your action. You have to remove all click event inside html

 $(".btn.btn-info.rep_data.tip-bottom").click(function(){
        var name=$(this).attr("name");
// you can get what ever it is 
// this.id;
// this.value

        });

DEMO

NOTE: Dont write event in html it is not good practis

Make button type submit with form tag

<form>
    <button type="submit" name="getTday">
     and so on...
</form>

Then you will get in php like $_GET['getTday'] this will get name attr of field so keep id and name same

else you need to use jquery/js to get id of button

add value attribute in your button like this value="getToday".

You can get this in php file.

Example

<button type="button" name="getTday" id="getToday" value="getToday" class="btn btn-info rep_data tip-bottom active" data-original-title="<?php echo $today;?>"onclick = "show()">Today</button>