ASP.NET - jQuery在Postback后无法工作
问题描述:
函数仅工作一次,但在页面加载后Postback
时失败。我是否缺少onclick
方法?ASP.NET - jQuery在Postback后无法工作
我的HTML:
<!-- Iframe Section -->
<div class="rmpView" id="ContentPlaceHolder1">
<iframe src="/Tabs/tabOne.aspx?ID=0" height="500" width="100%">
<html>
<head></head>
<body>
<div id="wrapper-iframe">
<label>Name:</label>
<input type="text"/>
<a href="javascript:void(0)" data-target="dBoxPopup" class="btn">Open Popup</a>
</div>
</body>
</html>
</iframe>
</div>
<!-- Iframe Section ENDS -->
<!-- Popup body -->
<div id="dBoxPopup" class="dialog-box">
<uc1:wucPopupContent runat="server" ID="wucPopupContent" />
</div>
<!-- Popup body ENDS -->
我的jQuery:
$("#ContentPlaceHolder1 iframe").load(function (e) {
// trigger popup onclick inside the iframe BEGINS
$(this).contents().find('.btn').on("click", function() {
var btnHref = $(this).attr("data-target");
javascript: popup(btnHref)
});
// trigger popup onclick inside the iframe ENDS
});
答
其中一个原因可能是因为回传后,该按钮是不能被发现。如果是这种情况,由于按钮本身不存在,弹出窗口不会被调用。