为什么当Jquery .on()事件方法被执行时,同一页面中的另一个.on()事件也总是被执行

时间:2015-09-24 20:17:37

标签: jquery

var $nav = $('.nav');
var $img = $('img');
$nav.on('click', function() {           
    //determine new position
    currentPosition = ($(this).attr('id')=='rightNav')
        ? currentPosition+1 : currentPosition-1;
    document.getElementById("pictureIndex").innerHTML = currentPosition + 1;                                    
    //hide/show controls
    manageNav(currentPosition);
    clearInterval(slideShowInterval);
    slideShowInterval = setInterval(changePosition, speed);
    moveSlide(slideWidth, currentPosition);
    console.log('end of nav function');
});

$img.on('click', function(){
    var path = traverseData(imgData,'path', $(this));
    window.location.assign("picturePage.html?name ="+path.name);
    return;
});

当调用$nav事件并执行其方法时,第二个事件被调用,但是在$nav而不是$img上,当然它不起作用,因为{{1 }}不能用于$nav函数。我尝试过一切,但每次都会发生!请帮我!

0 个答案:

没有答案