【发布时间】:2013-07-28 02:41:34
【问题描述】:
我正在尝试让magnific popup 包含一些表单。我想通过 html 锚点将变量传递给最终的弹出窗口。 作为此伪代码中的 Var1:
<!-- HTML launcher element -->
<a href="#test-popup?Var1=X" class="open-popup-link">Show inline popup</a>
<!-- Popup itself -->
<div id="test-popup">
<form method="post" action="">
<input type="hidden" id="myVar" name="Var1" value="[placeholder]" />
<input type="submit" />
</form>
</div>
<!-- Inizialization -->
<script type="text/javascript">
$(document).ready(function() {
$('.open_popup_link').magnificPopup({
type:'inline',
midClick: true,
function() {
**Here some magic code that sets Var1 = X **
$('#myVar').attr('value', function(i, attr){
return attr.replace('[placeholder]', Var1);
});}
});
});
</script>
我需要这个,因为我将生成服务器端(w. PHP)启动器,这样每个链接都会生成不同的表单数据。
编辑:我想到的一种方法是在启动器中使用自定义属性,例如:
<a href="#test-popup" data-var1="X" class="open-popup-link">Show inline popup</a>
但我无法真正获得正确的 jQuery 语法,用于在 magnific-popup 初始化中嵌套处理属性。 我的 js/jquery 知识非常基础,感谢您的任何提示。
【问题讨论】:
标签: javascript jquery magnific-popup