如何判断对象是否存在? if (document.all.button1){ document.all.button1.value="Hello World!";} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 document.all.button1 != nulltypeof(document.all.button1)=="undefined" if (button1){ button1.value="Hello World!"}if (button1 != null){ button1.value="Hello World!"}if (document.getElementById("button1") != null){ document.all.button1.value="Hello World!"} typeof(document.all.button1)=="undefined" 防止出错可以用try{//可能出错的代码;}catch(e){//出错后的处理。} 为什么在Firefox浏览器中这个JavaScript代码不能运行? 求 js正则表达式 怎样能在最短时间内学好JavaScript!!! 同一段js在TT或遨游等加壳浏览器中执行正常,IE中执行却被执行两次...请高人指点... 刚洗好澡,在线等 jS 表单处理问题,谢谢 ajax求救 求教:有谁知道defer的用法 用window.print()打印web窗体,如何去掉页眉和页脚? 如何让外部js脚本中的函数可以返回中文? 怎样得到表格中的控件 怎么样得到页面即将转向的下个url,马上接贴!
typeof(document.all.button1)=="undefined"
{
button1.value="Hello World!"
}if (button1 != null)
{
button1.value="Hello World!"
}if (document.getElementById("button1") != null)
{
document.all.button1.value="Hello World!"
}
try{//可能出错的代码;}
catch(e){//出错后的处理。}