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 = "";最终的解决方案! 关于checkbox的选中的问题 一个js小问题 javascript和java中的数据类型获取和转换问题 js动态绘制表格 怎么解决flash图片轮换效果中标题文字太长 这个效果要怎么写?在线等 Session("search_str")如何在javascript中赋值 如何用正则表达式验证多个IP 能否实现:一个button本来是'灰'的,担当页面中的任何一个checkbox被选中时, 正则问题 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 = "";最终的解决方案!