我在while循环中创建了一个按钮,然后将jquery函数传递给它。现在,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">×</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>
这是使用的代码。请详细说明。
答案 0 :(得分:2)
不是在<options>
标记中使用回调,而是将其添加到select
标记中。您无需在每个选项上附加回调。
它仅适用于select标签。
将select标签替换为:
<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>
希望它会有所帮助。