简体   繁体   English

jQuery函数不通过php循环多次调用

[英]jQuery Function not calling multiple times through php loop

I made a button inside a while loop and then passed a jquery function to it. 我在while循环中创建了一个按钮,然后将jquery函数传递给它。 Now the jquery function is working fine on the first button but doesn't work on other buttons. 现在,jquery函数在第一个按钮上运行良好,但在其他按钮上不起作用。

  <script> $(document).ready(function() { $("#myBtn").click(function() { var id = this.value; $("#myModal").modal(); $("#employee").change(function() { var eid = this.value; var dataString = 'id=' + id + '&eid=' + eid; $.ajax({ type: "POST", url: "ajax.php", data: dataString, success: function(result) { } }); }); }); }); /* $(document).ready(function(){ $("#myBtn").click(function(){ var id = this.value; if(id == true){alert(id++);} }); });*/ </script> 
 <div> <div class="panel"> <table id="basicTable" class="table table-striped table-bordered responsive"> <thead class=""> <tr> <th>S.No</th> <th>Title</th> <th>Lead Type</th> <th>Customer Name</th> <th>Customer Phone No.</th> <th>Customer Email</th> <th>Property Type</th> <th>Property Location</th> <th>Active</th> <th>Edit</th> <th>Assign</th> </tr> </thead> <tbody> <?php $que=mysqli_query($con,"select * from lms_table"); $number=1; while ($res=mysqli_fetch_array($que)) { $id=$res['lead_id']; $pt=$res['required_property_type']; ?> <tr> <td align="center"><?php echo $number; ?></td> <td align="center"><a href="comment.php?id=<?php echo $id; ?>"><?php echo $res['title']; ?></a></td> <td align="center"><?php echo $res['lead_type']; ?></td> <td align="center"><?php echo $res['customer_name']; ?></td> <td align="center"><?php echo $res['customer_no']; ?></td> <td align="center"><?php echo $res['customer_email']; ?></td> <?php $qe=mysqli_query($con,"SELECT * FROM `add_property_type` WHERE property_id='$pt'"); $re=mysqli_fetch_array($qe); ?> <!-- <td align="center"><?php// echo $re['property_type']; ?></td>--> <td align="center"><?php echo $res['required_property_type']; ?> <td align="center"><?php echo $res['property_required_location']; ?></td> <?php if($res['lead_status']==1){ ?> <td align="center"> <a class="tooltips" data-toggle="tooltip" title="Active" href="lead-active.php?l_id='<?php echo $id; ?>'&id=2"><i class="fa fa-user text-success"></i></a></td> <?php } else{ ?> <td align="center"> <a class="tooltips" data-toggle="tooltip" title="Inactive" href="lead-active.php?l_id='<?php echo $id; ?>'&id=1"><i class="fa fa-user text-danger"></i></a></td> <?php } ?> <td align="center"><a href="update-lms-table.php?id=<?php echo $id; ?>"><i class="fa fa-edit"></i></a></td> <td align="center"> <button type="button" class="btn btn-default " name ='but' id="myBtn" value="<?php echo $id['lead_id']; ?>" onclick='get_id(this.value)'>Assign</button> </td> </tr> <?php $number++; } ?> </tbody> </table> </div> <!-- panel --> </div> <!-- Modal --> <div class="modal fade" id="myModal" ?role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header" style="padding:35px 50px;"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> <h4 class="modal-title" id="exampleModalLabel">Assign Employee</h4> </div> <div class="modal-body" style="padding:40px 50px;"> <form action="half.php"> <select class="form-control select1 " id="employee"> <option selected value="">Select Employee</option> <?php $que1 =mysqli_query($con,"select * from add_employee"); while($r=mysqli_fetch_array($que1)){ $empid=$r['employee_code']; echo "<option value='$empid' onchange='get_id(this.value)'>".$r['employee_first_name']."</option>"; } ?> </select> </div> <div class="modal-footer"> <button type="button" class="btn btn-success btn-default" data-dismiss="modal" ><span class="glyphicon glyphicon-off"></span> Login</button> <button type="submit" class="btn btn-danger btn-default pull-right" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Cancel</button> </form> </div> </div> </div> </div> </div> 

This are the code used. 这是使用的代码。 Please shed some light. 请说明一下。

Instead of using the callback in the <options> tag, add it to the select tag. 而不是在<options>标记中使用回调,而是将其添加到select标记中。 You do not need to attach the callback on every option. 您无需在每个选项上都附加回调。

It will work with the select tag alone. 它将仅与select标记一起使用。

Replace your select tag with this: 将您的选择标签替换为:

<select class="form-control select1 " onchange='get_id(this.value)' id="employee">
        <option selected value="">Select Employee</option>
        <?php
            $que1 =mysqli_query($con,"select * from add_employee");
            while($r=mysqli_fetch_array($que1))
            {
                $empid=$r['employee_code'];
                echo "<option value='$empid'>".$r['employee_first_name']."</option>";
            }

                                                ?>
</select>

Hope it would help. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM