Jquery里报undefined错误 var mytitle = "";mytitle = this.alt;this.alt = "";当网页下载局部时,有时候mytitle的值为undefined,请问怎么解决? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 mytitle = typeof(this.alt)==undefined?"":this.alt; mytitle = this.alt;上面一句话的位置要放到 this.alt赋值后的下面 mytitle的值为undefined,说明this.alt值没拿到。 var mytitle = "";this.alt = "";mytitle = this.alt;顺序 不是顺序问题,如果var mytitle = "";this.alt = "";mytitle = this.alt;这样,那么mytitle就永远为空了!我试了二楼的作法,还是有问题,谢谢各位了。 var mytitle='';try {mytitle = this.alt;}catch(err){}这样不知行不? if ($(this).attr("alt") == "undefined") { $(this).attr({ "mytitle": "请刷新网页以加载说明文字……", "alt": "" }); } else { this.mytitle = this.alt; this.alt = ""; }这样解决了。 this.mytitle = (this.alt == "undefined" ? "请刷新网页以加载说明文字……" : this.alt);this.alt = "";最终的解决方案! JavaScript函数调用问题 想通过js自动提交表单,但是却不执行Onsubmit的事件,怎么办? JS简单问题 大家帮忙看看这个字符串怎么写? 地图上光标样式问题 怎么这个xml用javascript,在火狐下调试不成功???? [求助]javaScript下拉菜单的不能正常显示呀~· jquery求助 ? jQuery19106593590301938974="514" 有关一个关闭窗口的问题,菜鸟在此谢各位 我怎样使新打开的窗口位于屏幕的中间? js联级菜单的难点问题 extjs formpanel 连接错误
上面一句话的位置要放到 this.alt赋值后的下面
mytitle的值为undefined,说明this.alt值没拿到。
this.alt = "";
mytitle = this.alt;顺序
var mytitle = "";
this.alt = "";
mytitle = this.alt;
这样,那么mytitle就永远为空了!我试了二楼的作法,还是有问题,谢谢各位了。
try {
mytitle = this.alt;
}
catch(err){}这样不知行不?
if ($(this).attr("alt") == "undefined") {
$(this).attr({ "mytitle": "请刷新网页以加载说明文字……", "alt": "" });
} else {
this.mytitle = this.alt;
this.alt = "";
}这样解决了。
this.mytitle = (this.alt == "undefined" ? "请刷新网页以加载说明文字……" : this.alt);
this.alt = "";最终的解决方案!