Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用jquery查询表中按钮的id? 电子邮件 名称 主题 消息_Php_Jquery - Fatal编程技术网

Php 如何使用jquery查询表中按钮的id? 电子邮件 名称 主题 消息

Php 如何使用jquery查询表中按钮的id? 电子邮件 名称 主题 消息,php,jquery,Php,Jquery,“id”总是用来标识某些东西,因此应该是唯一的。所以你首先要让它独一无二。这样的办法应该行得通 <table id="example1" class="table table-bordered table-striped"> <thead> <tr> <th>Email</th&g

“id”总是用来标识某些东西,因此应该是唯一的。所以你首先要让它独一无二。这样的办法应该行得通

    <table id="example1" class="table table-bordered table-striped">
                        <thead>
                          <tr>
                            <th>Email</th>
                            <th>Name</th>
                            <th>Subject</th>
                            <th>Message</th>
                          </tr>
                        </thead>
                        <tbody>
                          <?php 
                          foreach($fetchContactData as $value)
                          {
                            ?>
                            <tr>
                              <td><?php echo $value['email'] ?></td>
                              <td><?php echo $value['name']?></td>
                              <td><?php echo $value['subject'] ?></td>
                              <td><button type="button" class="btn btn-warning" value="<?php echo $value['message'] ?>">Show</button></td>
                              <?php   
                            }?>


                          </tbody>
                          <tfoot>
                            <tr>
                              <th>Email</th>
                              <th>Name</th>
                              <th>Subject</th>
                              <th>Message</th>
                            </tr>
                          </tfoot>
                        </table>



      Js code:
    <script type="text/javascript">
        $(document).ready(function(){
          $("#example1 button").click(function(){

          var id=$(this).attr('value');


          });
        });
      </script>

电子邮件
名称
主题
消息

您的id=按钮进入循环,因此不是唯一的。 我建议您不要使用id,最好使用类之类的东西,并在js脚本中单击以下内容:

<script>
$( "button[id^='show-']" ).on('click', clickhandler);
</script>

您的按钮的id似乎总是相同:
id=“show”
您谈到jquery,但代码中的id在哪里?这里没有javascript。我们当然不可能是那种千里眼。兄弟,我确实尝试了我所有的jquery逻辑,但它不起作用,我只需要点击那个按钮的按钮idonly@prashant欢迎使用SO,不幸的是,
id=“show”
不是唯一的,它会在PHP循环中迭代!好吧,我明白你的意思,把代码改成我想要的。我将$value['id']更改为$value['message'],所以现在这包含了一条长消息,我想将这条消息显示到引导模式类divYes Bro中,我明白你的意思,但我现在更改了代码。当$value['message']存在时,当前代码不起作用,但相同的代码与$value['id']起作用。注意:我的代码不带$i,您建议@clashSo您想知道“id”属性中写了什么吗?在jQuery$(selector.attr('id')中;
<script>
$( "button[id^='show-']" ).on('click', clickhandler);
</script>
<td><button type="button" class="btn btn-warning button_msg"  value="<?php echo $value['message'] ?>">Show</button></td> 
  $(".button_msg').click(function(){
//Do anything
})