结论:我正在寻找有关如何修复代码的建议,这样当我点击一个链接时,它会打开一个弹出窗口(当前确实如此)并移动一个变量用于php。
我有一个脚本,可以在同一个窗口中生成一个弹出窗口,同时使其他所有内容变灰。我想这样做,但允许链接最终选择哪个php文件填充弹出div。请帮忙。弹出窗口效果很好,但div的变量不是那么多。
def new
@shop = Shop.find(params[:shop_id])
@item = @shop.items.new
end
供参考,这是测试中的当前页面:http://wolfpackhome.myqnapcloud.com/jquerypopuptest
答案 0 :(得分:1)
$(document).ready(function() {
$('#fadeandscale').popup({
pagecontainer: '.container',
transition: 'all 0.3s', onopen: function() {
}
});
$('a[name="link"]').click(function() {
$('#linkName').html("Link name:" + this.id);
$.ajax({
url: "modal.php?id=" + this.id,
success: function(resdata) {
if (resdata != null ) {
$('#fadeandscale').html(resdata);
$('#fadeandscale').popup('show');
}
}
});
$.fn.popup.defaults.pagecontainer = '.container'
});
});
// Html code
<div class="container">
<!-- Add an optional button to open the popup -->
<a class="initialism fadeandscale_open btn btn-success" name="link" id="Link1" href="#">Link 1</a>
<a class="initialism fadeandscale_open btn btn-success" name="link" id="Link2" href="#">Link 2</a>
<!-- Add content to the popup -->
<div id="fadeandscale" class="well">
</div>
</div>
----- modal.php
<?php
$linkname = $_GET["id"];
?>
<span id="linkName"><?php echo $linkname; ?></span>
<div id="close">
<a class="fadeandscale_close">Close</a>
</div>
I have made below changes
1. Changed href as "href=#"
2. Added id and name for the anchor element
3. Added click handler for the anchor element and triggered the ajax call.
4. Moved the popup code to Modal.php and called through ajax.
It looks not possible to pass the value with help of popup, so i made these changes.
答案 1 :(得分:0)
尝试使用AJAX
打开您的弹出窗口,这样您就可以通过GET
轻松地在网址中发送变量,