$("#light tr td").each(function(i){
if($(this).attr("lang")!=undefined && $(this).attr("lang") == "tdTitle"){
if($(this).attr("id")==undefined || isNaN($(this).attr("id"))){
if($(this).text().length>200){
//$(this).attr("title",$(this).text());
$(this).text($(this).text().substring(0,200)+"...");
}
}else{
var length=$(this).attr("id");
if($(this).text().length>length){
$(this).text($(this).text().substring(0,length-4)+"...");
}
}
}
});
if($(this).attr("lang")!=undefined && $(this).attr("lang") == "tdTitle"){
if($(this).attr("id")==undefined || isNaN($(this).attr("id"))){
if($(this).text().length>200){
//$(this).attr("title",$(this).text());
$(this).text($(this).text().substring(0,200)+"...");
}
}else{
var length=$(this).attr("id");
if($(this).text().length>length){
$(this).text($(this).text().substring(0,length-4)+"...");
}
}
}
});
本文介绍了如何通过JavaScript遍历指定元素,并针对特定属性(如lang为'tdTitle')调整内容长度,确保网页标题不超过200字符,对于ID存在且长度超过200字符的情况,则将文本截取并添加省略号。
1295

被折叠的 条评论
为什么被折叠?



