php - How select button in JQuery -
<?php foreach ($list $item): ?>   <tr>     <td>     <div id="<?php echo $item['id']; ?>">     <input type="text" name="name" id="name"/>     <button type="submit" id="ajax_submit" value="<?php echo $item['id']; ?>">run</button>     </div>     </td>   </tr> <?php endforeach; ?>   in php-code generate html table. when user click on button activate jquery script
 <script>    $(document).ready(function(){      $('button').click(function(){        var id = "#" + $("button").val();           $.post("data/js", { name: $("#name").val(),id : id },            function(data){             $(id).html(data);          });        })     });  </script>   but, when want select non-first button in table, script run function first. please normal.
ps sorry english ;-(
try this:
<?php foreach ($list $item): ?>   <tr>     <td>     <div id="<?php echo $item['id']; ?>">     <input type="text" name="name" id="name"/>     <button type="submit" id="ajax_submit_<?php echo $item['id']; ?>" value="<?php echo $item['id']; ?>">run</button>     </div>     </td>   </tr> <?php endforeach; ?>   ..
<script>    $(document).ready(function(){      $('button').click(function(){        var id = $(this).attr('value');           $.post("data/js", { name: $(this).prev().attr('name'),id : id },            function(data){             $(id).html(data);          });        })     });  </script>      
Comments
Post a Comment