问题
Function works one time only but fails when page loads after Postback
. Am I missing something with onclick
method?
My 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 -->
My 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
});
回答1:
One reason could be that after the post back, the button is not able to be found. If this is the case, the popup will not be invoked since the button itself is not present.
来源:https://stackoverflow.com/questions/39095879/asp-net-jquery-is-not-working-after-postback