Internet Explorer 11中的JavaScript错误

4
我有一个表单页面,可以从弹出窗口向数据库提交数据。我为提交数据添加了一个禁用的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>

<script language="javascript" type="text/javascript"> function disableButtonOnClick(oButton, sButtonText, sCssClass) { 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> - Avy
Avyy,哈哈,我会把它添加到问题中。 - Mathemats
但与脚本无关。我猜测这可能是浏览器问题。 - Avy
1
在IE中,前往“设置 -> Internet选项 -> 高级 -> 浏览 -> 禁用脚本调试(Internet Explorer)”,并取消勾选该选项。如果遇到JavaScript错误,IE将在错误处中断,并可以打开调试窗口。您将能够准确定位错误和错误所在的行号。 - TejSoft
你为什么要使用 setAttribute 而不是直接设置属性呢? - Jeremy J Starcher
1个回答

0

尝试下面的代码

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接