我有動態表,並在按鈕值我存儲每個ID的值。 我需要將該ID傳遞給模態並在模態中執行一些查詢。我會通過php來做到這一點。按鈕值傳遞到模態
<td><button="type" class="btn btn-success btn-sm" onclick="getNarudzbaId(this)" value="<?php echo $r['id'];?>" data-toggle="modal" id="modal" data-target="#modal_theme_success">Pregled <i class="fa fa-play position-right"></i></a></td>
<script type="text/javascript">
function getNarudzbaId(object) {
var x = $(object).attr("value");
$.ajax({
type: "GET",
url: "pregled.php",
data:{name:x},
success: function(data){
alert("return here if success")
}
})
}
</script>
其實我想要在模態窗口中傳遞值,它在同一個頁面上的按鈕是。
這裏是我的模態
<div id="modal_theme_success" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header bg-success">
<button type="button" class="close" data-dismiss="modal">×</button>
<h6 class="modal-title">Stavke naloga</h6>
</div>
<div class="modal-body">
<h6 class="text-semibold">Text in a modal</h6>
<p>Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<hr>
<?php
$temp = $_POST['name'];
echo $temp;
?>
<h6 class="text-semibold">Another paragraph</h6>
<p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-link" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-success">Save changes</button>
</div>
</div>
</div>
</div>
我從來沒有發送數據前,模態,任何幫助是非常讚賞
嘗試讀取這個答案:http://stackoverflow.com/questions/10626885/passing-data-to-a-bootstrap-modal – DekiChan