0
我使用jQuery創建了一個內聯編輯輸入['text'] snippet。使用jQuery從附加元素中選擇一個類
的HTML將是這樣的:
<div id="inline">
<span class="item">Color</span>
</div>
我被困在此處(here是我的代碼):
$('.item').each(function(){
$(this).click(function(){
$(this).hide();
$(this).parent().append(
'<form method="post" action="" id="inline_form">'+
'<input type="text" value="'+ $(this).html() +'"> <input type="Submit" value="update" />'+
' <a href="#" class="cancel">Cancel</a></form>'
);
});
});
我要綁定一個click事件類 '.cancel'我已經在上面添加了,所以當我點擊取消時,它將刪除表單'#inline_form'並顯示'.item'
我試過這個
$('.cancel').each(function(){
$(this).click(function(){
$(this).parent('#inline').find('.item').show();
$(this).parent('#inline_form').remove();
});
});
但它沒有奏效。 如何選擇「.cancel」,以便我可以在上面放置點擊事件?
」這裏的關鍵點是您必須在創建鏈接的同時指定取消功能,因爲在此之前鏈接不存在。「 現在您已經提到了它。多謝。 – mdennisa 2009-11-12 03:51:10