这是我的javascript函数,我想在我的bootstrap模型表单中附加SEARCHID。 如何在我的引导模型表单中获取该ID
这是我的引导模型隐藏字段
<input type="hidden" name="ID" value="ID" id="searchid">
这是我在这些函数中的javascript函数,当用户点击按钮
时,我得到了我的idfunction searchitem(id)
{
var SEARCHID = id;
console.log(SEARCHID);
}
<a class="btn btn-primary text-capitalize ct-js-btnEdit--Agents btn-sm" id="<?php echo $DETAILS->id;?>" value="<?php echo $DETAILS->id;?>" onclick="searchitem(this.id);"><i class="fa fa-pencil"></i> Edit</a>
答案 0 :(得分:0)
尝试以下解决方案,添加注释以解释过程
//on button click
$("#yourPHPId").on("click", function() {
//get the id from the button element
var searchId = $("#searchid").attr("id");
//append to modal-body (inside p tag if preferred)
$(".modal-body p").append("Hidden field id = " + "<b>" + searchId + "</b>");
});
//on modal hide
$('#myModal').on('hidden.bs.modal', function() {
//empty the modal body (<p>) contents
$(".modal-body p").empty();
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<input type="hidden" name="ID" value="ID" id="searchid">
<!-- Trigger the modal with a button !-->
<!-- Insert your PHP functions here as required, they have been taken out in order for the code snippet to work !-->
<a class="btn btn-primary" id="yourPHPId" data-toggle="modal" data-target="#myModal"><i class="fa fa-pencil" ></i> Edit</a>
<!-- Modal !-->
<div id="myModal" class="modal fade" 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">
<p></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>