繁体   English   中英

锚标记中的Javascript在FireFox和IE中不起作用。 可以在Chrome浏览器中使用

[英]Javascript in anchor tag not working in FireFox and IE. Does work 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>

我建议您使用jQuery之类的库,并将click事件绑定到该元素

如果必须使用内联Javascript,通常至少使用HTML onclick属性也更可靠。 如果这样做,我建议您不要使用'a'标记,这样就不必处理默认行为即链接。 使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM