我的代码是:
$(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
我不知道是什么导致了这个错误。
另外,如何将counter()
的功能的值传递给$("#head").click
?我不能直接提到$("#head")
,因为我会在重复使用函数计数器中的代码的同时使用除#head
之外的更多div来重复此功能。
请不要问多个问题。问一个或另一个 – Liam