我的代码是:
$(document).ready(function(){
var hCount = 0,
eCount = 0,
nCount = 0,
mCount = 0;
$("#head").click(function() {
var pPos = counter(hCount);
$(this).animate({left:pPos+"px"}, 1000);
});
function counter(count)
{
count++;
if(count === 10)
{
count = 0;
pPos = 0;
}
else
{
var pPos = $(this).css('left');
pPos = pPos.substring(0,(pPos.length-2))
pPos -= 367;
}
return pPos;
}
我收到了一个错误,内容为:
Uncaught TypeError: Cannot read property 'defaultView' of undefined
我不知道是什么导致了这个错误。
另外,我该如何将 $(this)
的值作为参数传递给 counter()
函数?由于我会在其他不同的 div 中重复使用这个功能,因此不能直接提及 $("#head")
,而需要在函数 counter 中重用代码。