我試圖創建一個「就地編輯」表格單元格。您點擊一個編輯鏈接,並在其位置顯示一個文本區域。當我將鼠標懸停在表格行上時,我也只想顯示編輯鏈接。我遇到的問題是,當您將鼠標懸停在表格行上時,編輯鏈接始終顯示。我怎樣才能讓它隱藏/顯示,只發生在你目前沒有編輯的時候。jQuery:只有當子元素沒有被點擊時,如何將效果應用於父元素?
HTML:
<td><a class="edit">Edit</a> $100</td>
的jQuery:
$(document).ready(function(){
$('a.edit').hide();
$('tr').hover(
function(){
$(this).find('a.edit').show();
},
function(){
$(this).find('a.edit').hide();
}
);
$('a.edit').click(function(e){
e.preventDefault();
$(this).hide();
$(this).after('<input type="text" style="width:100%;" />');
});
});
你想如何退出編輯模式? – 2010-10-19 19:43:22