有许多order_id但想将该ID传递给我选择的弹出框
<a rel="dialog" data-toggle="modal" data-id="<?=$order_id ?>" href="#mymodal" data-target="#myModal" ><?php echo "<br> $order_id </br>";?></a>
//这是我用于将特定值传递给弹出框的脚本
<script>
$(document).ready(function(){
...
$("a[rel=dialog]").each(function(){
var id = this.getAttribute("data-id");
$('#products_id_textbox').val(id);
$('#products_modal_box').dialog('close');
});
</script>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<table class="table table-hover table-bordered" >
<tr style=" background-color:#00AAAD; color:#FFF; ">
<td>Passenger Name </td>
<td>Mobile No</td>
</tr>
<?php echo $order_id;?>
答案 0 :(得分:0)
运行代码段&amp;检查输出。我希望这是你想要的:
$(document).ready(function(){
$("a[rel=dialog]").click(function(){
var id =$(this).attr("data-id");
$('#products_id_textbox').val(id);
console.log("Order id-"+id);
});
});
&#13;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<a rel="dialog" data-toggle="modal" data-id="1" href="#mymodal" data-target="#myModal" >1</a>
<a rel="dialog" data-toggle="modal" data-id="2" href="#mymodal" data-target="#myModal" >2</a>
<a rel="dialog" data-toggle="modal" data-id="3" href="#mymodal" data-target="#myModal" >3</a>
<a rel="dialog" data-toggle="modal" data-id="4" href="#mymodal" data-target="#myModal" >4</a>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
Order Id : <input type="text" id="products_id_textbox"/>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
&#13;