当我尝试用javascript / jquery用其他特定文本替换某些文本时,我收到此错误。
这是错误:
未捕获TypeError:对象[object HTMLAnchorElement]没有方法'html'
以下是网站上的javascript行:
$(document).ready({
var navigationLinks = $('.nav a');
for(var i=0; i < navigationLinks.length; i++){
var thisLink = navigationLinks[i];
switch(thisLink.html()){
case "About":
thisLink.html().replace(/About/g,'');
case "Work":
thisLink.html().replace(/Work/g,'');
case "CV":
thisLink.html().replace(/CV/g,'');
case "Resume":
thisLink.html().replace(/Resume/g,'');
case "down":
thisLink.html().replace(/down/g,'');
case "Mail":
thisLink.html().replace(/Mail/g,'');
case "Dribbble":
thisLink.html().replace(/Dribbble/g,'');
case "GooglePlus":
thisLink.html().replace(/GooglePlus/g,'');
case "Facebook":
thisLink.html().replace(/Facebook/g,'');
case "Twitter":
thisLink.html().replace(/Twitter/g,'');
default:
thisLink.html().replace(thisLink.html(),thisLink.html());
}
}
window.onscroll=scrollFunc;
});
答案 0 :(得分:3)
变化:
navigationLinks[i]; // DOM element which doesn't have an `html` function
要:
navigationLinks.eq(i);// jQuery wrapper which does have an `html` function
答案 1 :(得分:0)
.html()是一个jquery方法。你想要
$(thislink).html()