简体   繁体   English

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

[英]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.

相关问题 Javascript / jQuery无法在Firefox,Safari和IE中运行。 精通Opera和Chrome - Javascript/jQuery not working in Firefox, Safari and IE. Fine in Opera and Chrome Jquery / Javascript和Css条件在firefox和IE上不起作用。 它适用于Chrome - Jquery/Javascript and Css condition doesn't work on firefox and IE. It works on Chrome Onclick在IE或Firefox中无法使用,但在Chrome中可以使用 - Onclick not working in IE or Firefox but does work in Chrome 为什么javascript函数在firefox中可以工作,但在Chrome或IE上却不能工作 - Why does a javascript function work in firefox but not work on Chrome or IE Javascript函数不适用于Firefox,但适用于Chrome,Safari,IE和Edge - Javascript function does not work in firefox but does in chrome, safari, IE and edge Javascript在chrome中工作,而不是firefox或ie - Javascript working in chrome, not firefox or ie Javascript可在Firefox中运行,但不能在IE或Chrome中运行 - Javascript working in firefox but not IE or chrome 为什么这段JavaScript既可以在Google Chrome和IE上运行,又不能在Firefox中运行? - Why does this piece of javascript work on both Google Chrome and IE but not in Firefox? 锚标签上的onclick事件在IE中有效,但在Firefox和Chrome中无效 - onclick event on anchor tag works in IE, but not in Firefox and Chrome 使用$ .getJSON(),我无法在任何版本的IE中接收结果。 Firefox / Chrome正常运行 - Using $.getJSON() I can't receive results in any version of IE. Firefox/Chrome work ok
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM