我在下面的代码中使用href链接打开弹出窗体。如何将参数传递给此弹出窗体?
echo "<a class=\"btn btn-primary btn-xs\" href=\"#contactAdvertiser\" data-toggle=\"modal\" ><i class=\"fa fa-edit\"></i> Reply </a></p>";
答案 0 :(得分:0)
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
</head>
<body>
this is a simple way only
i make use of bootstrap and jquery
<br/>
this are buttons generated by the php
<br/>
you can create a element data attribute where in you can put
<br/>
your php contents to be transfer to the modal or popup
<br/>
<button type="button" class="btn btn-primary clickbutton" data-toggle="modal" data-target=".bs-example-modal-sm" data-transfer="This is a data that i am holding generated by the php">Small modal</button>
<button type="button" class="btn btn-primary clickbutton" data-toggle="modal" data-target=".bs-example-modal-sm" data-transfer="This is a data that i am holding generated by the php sample 2">Small modal1</button>
<div id="popup" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<p>Sample Test Data</p>
</div>
</div>
</div>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.3.min.js"></script>
<script src="bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// bind on click event on the button once it was open
// change the contents of modal or the popup
// contents
$('.clickbutton').on('click', function() {
// get the data-transfer attribute and
// send it to modal/popup data
var data = $(this).attr('data-transfer');
// change the content of the modal using javascript
// jquery dom manipulation
$('#popup').find('.modal-content p').html(data);
});
});
</script>
</body>
</html>