我对这个主题找不到答案,但没有一个能帮助我。
我点击第二次点击即可点击 - 问题出在哪里?
<script type="text/javascript">
$(function () {
$("#back-in-stock-subscribe").click(function () {
var sku = document.getElementById('back-in-stock-sku-to-get').textContent;
var action = '@Url.RouteUrl("BackInStockSubscribePopup", new { productSku = "sku" })';
action = action.replace("sku", sku);
$("#back-in-stock-subscribe").fancybox({
'href': action,
'transitionIn': 'none',
'width': 500,
'height': 200,
'type': 'iframe',
'centerOnScroll': true
});
});
});
</script>
答案 0 :(得分:0)
我相信你的点击代码会初始化花哨的盒子,但你需要调用fancybox本身的click事件来启动它。
尝试在最后添加.click():
<script type="text/javascript">
$(function () {
$("#back-in-stock-subscribe").click(function () {
var sku = document.getElementById('back-in-stock-sku-to-get').textContent;
var action = '@Url.RouteUrl("BackInStockSubscribePopup", new { productSku = "sku" })';
action = action.replace("sku", sku);
$("#back-in-stock-subscribe").fancybox({
'href': action,
'transitionIn': 'none',
'width': 500,
'height': 200,
'type': 'iframe',
'centerOnScroll': true
}).click();
});
});
</script>
看着这个: