weixin_33744141 2011-12-14 12:34 采纳率: 0%
浏览 19

找不到JavaScript错误

I would like to add new attribute to select box which name and id are 'firm_id'. So far I have tried with this code, its working fine in mozila but not working in IE.

I am doing this with javascript because select box is coming from ajax. The function sbmtfrm() is not calling in IE.

Error: Message: 'FB' is undefined.

May be FB is a object called in my js lib files, but now i am writing code within a another saperate script tag.

<script type="text/javascript">

    function sbmtfrm()
    {
       alert('now submitting...');
       document.frmsearch.submit();
    }

    function setOnclickAtt(name)
    {
        alert("'"+name+"'" + document.getElementById(name).getAttribute('onchange'));
        alert(document.getElementById(name));
        if(document.getElementById(name))
        {
            alert('attrr changed');
            var ref = document.getElementById(name);
            ref.setAttribute('onchange', 'sbmtfrm();');
            alert("now new atrr = " + document.getElementById(name).getAttribute('onchange'));
        }
        else
        {
            alert('again');
            setTimeout("setOnclickAtt('firm_id')",100);
        }
    }

    setOnclickAtt('firm_id');

</script>   

Any suggestion or ideas would be greatly appreciated.

Thanks a lot.

  • 写回答

1条回答 默认 最新

  • weixin_33705053 2011-12-14 12:42
    关注

    I think IE is picky when it comes to event handling. Try:

    ref.onchange = sbmtfrm;
    

    instead of:

    ref.setAttribute('onchange', 'sbmtfrm();');
    

    Also, I think the error message has nothing to do with this issue. It´s wrong but it´s another issue.

    评论

报告相同问题?

悬赏问题

  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译