Uncaught TypeError: Cannot read property ‘split’ of undefined

问题 :Uncaught TypeError: Cannot read property ‘split’ of undefined
at HTMLLIElement.

split()切割的问题 因为遍历ul的时候,第一次会得到一个空值,这个是通过输出遍历的对象知道的,最后我在使用split()的时候加了一个判断(就是判断要切割的字符串是不是存在)

$(".type_ul").find('li').each(function () {
var zhi=$(this).find('a').attr("href");
if (zhi) {
var qwe=zhi.split('.')[0];
console.log(qwe);
}
})

猜你喜欢

转载自www.cnblogs.com/lsyy2017/p/10775933.html