【问题标题】:JavaScript Error in Internet Explorer 11Internet Explorer 11 中的 JavaScript 错误
【发布时间】:2015-06-14 07:28:18
【问题描述】:

我有一个表单页面,它从弹出窗口向数据库提交数据。我为提交数据添加了一个禁用按钮 js。它在 ie11 上不起作用,但在其他浏览器上完美运行。

  <script language="javascript" type="text/javascript">
    // disables the button specified and sets its style to a disabled "look".
    function disableButtonOnClick(oButton, sButtonText, sCssClass)
    {
        // set button to disabled so you can't click on it.
        oButton.disabled = true; 
        // change the text of the button.
        oButton.value = sButtonText; 
        // IE uses className for the css property.
        oButton.setAttribute('className', sCssClass); 
        // Firefox, Safari use class for the css property. 
        oButton.setAttribute('class', sCssClass);
    }
</script>

【问题讨论】:

  • Avyy lmao,我会把它添加到问题中。
  • 但与脚本无关。我猜它有一些浏览器问题。
  • 在 IE 上转到“设置 -> Internet 选项 -> 高级 -> 浏览 -> 禁用脚本调试 (Internet Explorer)”并取消选中该选项。如果你遇到 javascript 错误,IE 会在错误上中断,你可以打开一个调试窗口。您将能够查明错误以及遇到错误的行号。
  • 为什么要使用setAttribute而不是直接设置属性?

标签: javascript c# asp.net internet-explorer internet-explorer-11


【解决方案1】:

试试下面的代码

if((navigator.userAgent.indexOf("MSIE") != -1 )
oButton.setAttribute('className', sCssClass); 
else
oButton.setAttribute('class', sCssClass);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    相关资源
    最近更新 更多