[英]Javascript in anchor tag not working in FireFox and IE. Does work in Chrome
I'm trying to debug a browser issue. 我正在尝试调试浏览器问题。 The user can click the Change Password button which brings up a colorbox modal popup. 用户可以单击“更改密码”按钮,这会弹出一个颜色框模式弹出窗口。 If they click "Yes" nothing happens in Firefox or IE, but it works in Chrome. 如果他们单击“是”,则在Firefox或IE中什么也不会发生,但在Chrome中有效。
<a href="#doneChangePassword" id="changePasswordActivate" class="right modal button">Change Password</a>
**<input class="hidden" type="submit" id="changePasswordButton" value="Change Password" />**
</section>
<div id="changePasswordContainer" class="modal_container confirm">
<div id="doneChangePassword">
<div>
<div style="padding:10px;">
<p style="font:size: 18px; text-align: center;">You are changing the password for<br /><strong>@TempData["UserFullName"]</strong>.</p>
<div style="width: 180px; margin: 0 auto; text-align: center;">
<p style="margin: 0 0 10px 0;">Are you sure?</p>
<div class="closeBox right button_disabled_plain" onclick="$.colorbox.close();">No</div>
**<a href="javascript:$.colorbox.close();document.getElementById('changePasswordButton').click();return false;" class="left button">Yes</a>**
<div class="clr"></div>
</div>
</div>
</div>
</div>
</div>
I suggest you use a library like jQuery and bind a click event to the element 我建议您使用jQuery之类的库,并将click事件绑定到该元素
If you must do inline Javascript, It is also usually more reliable at least to use the HTML onclick attribute. 如果必须使用内联Javascript,通常至少使用HTML onclick属性也更可靠。 If you do this I suggest you don't use the 'a' tag so you don't have to deal with the default behavior of it being a link. 如果这样做,我建议您不要使用'a'标记,这样就不必处理默认行为即链接。 Use a span or div and style it how you like. 使用span或div并根据需要设置其样式。
<span onclick="myfunction()" class="left button">Yes</span>
<script type="text/javascript">
// as pointed out by the comment, the colorbox library may not have loaded yet..
// if using jquery you could wrap this function in the page load event
function myfunction() {
$.colorbox.close();
document.getElementById('changePasswordButton').click();
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.