javascript not calling in IE9

对着背影说爱祢 提交于 2019-12-12 10:48:33

问题


I created a textbox and wrote onfocus="getFocus()"

Now I wrote function in javascript

function getFocus()

        {
            alert('Hello I Got Focus !!');
        }

The problem is in IE8 it worked perfectly, but in IE9 alert is not showing. Can anyone tell what is wrong with the code ??

I also tried

txtAmt.Attributes.Add("onfocus","getFocus()")

but still it didn't worked

i too tried

txtAmt.Attributes.Add("onfocus","javascript:getFocus();")

Now i am worried.. what to do ??


回答1:


Open up the IE developer tool (F12) after your page is loaded.

Check the Browser Mode: and Document Mode:

Try setting Browser Mode to IE9, and Document Mode to IE9 Standards.

Now try again and see if that works.




回答2:


onFocus should be re-written as onfocus = "getFocus()".

If it still doesn't work, then if IE9 is newly installed, you might want to check if Javascript is enabled in your installation of IE9. :)




回答3:


try javascript tag :

txtAmt.Attributes.Add("onfocus","javascript:getFocus();")

  1. javascript doesn't fire if there is any error in page. Check for any error by enabling javascript debugging.
  2. Some old versions of jquery is not supported in ie9 (version below 1.4.1)



回答4:


Your code seems fine, have you tried checking the security settings of IE?

if you go

 Internet Options > Security > Custom level > 

 Make sure Active Scripting is not set to Disabled


来源:https://stackoverflow.com/questions/8179350/javascript-not-calling-in-ie9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!