Internet Explorer 6,7,8上的javascript错误,“是null或不是对象“
问题描述:
当我启动index.php时,它调用我的javascript文件,该文件包含以下代码:
when I start my index.php it calls my javascript file that has this code below:
当应用程序立即启动时出现此错误:
when the application starts immediately this error appears:
这只能发生在互联网浏览器上,index.php上没有'txtName',因为。每个页面调用js,有什么方法可以改进这个功能吗? tath我不需要手动将js放在每一页中吗?
and this can only happen on the internet explorers, there is no 'txtName' on index.php, because the. js is called for every page, there any way to improve this function ? tath i dont need to put manually the js in each page?
任何人都知道如何解决这个问题?非常感谢...
Anyone know how can I solve this ? Thank you very much...
答
为什么不为此方法设置条件:
在这种情况下:
Why dont you put a conditional for this method: In this case:
var iId = document.getElementById('txtName');
if(iId != null)
{
// Processing
}