2013-05-03 29 views
2

我有一個列表,我在屏幕加載後追加到列表。我想在懸停後將光標更改爲指針。到目前爲止,我嘗試使用.on事件,但它似乎並沒有工作。 ('。item')。on('mouseover',function(){('。item')。css('cursor','pointer');
});如何使用JQuery將鼠標懸停在動態列表上時將指針更改爲指針

$(document).ready(function() { 
    $('input').focus(function() { 
     $('input[name=checklistInput]').css('outline-color','#FF0000'); 
    }); 
    $('#add').click(function() { 
     var toAdd = $('input[name=checklistInput]').val(); 
     $('.list').append('<div class="item">' + toAdd + '</div>'); 
     $('input[name=checklistInput]').val(''); 
    }); 

    $('.item').on('mouseover', function() { 
     $('.item').css('cursor', 'pointer');  
    }); 

    $(document).on('click','.item', function() { 
    $(this).remove(); 
    }); 
}); 

讓我知道你是否需要更多關於上述代碼總體目標的更多細節。

感謝,

+0

問題是當你點擊事件做不使用代表團鼠標懸停事件。順便說一句,你應該使用$(this)內部鼠標懸停回調函數 – 2013-05-03 14:56:51

回答

2

如何使用純CSS使用:hover

.item:hover { cursor: pointer; } 

如果必須使用JavaScript,使用mouseenter代替mouseover以及重置爲默認的mouseleave

+0

嗯是的。那太容易了。我不應該試圖強制JQuery。謝謝! – 2013-05-03 14:55:19

1

你可以使用普通的CSS來實現這一點。使用:懸停沒有任何意義。

.item{ 

cursor:pointer; 
} 
0

只是在你的代碼的CSS

.item:hover {cursor : pointer} 
相關問題