如果用戶點擊「添加」,我需要暫時禁用所有添加/刪除偵聽器,直到myid失去焦點。jQuery插入/刪除網格
<!DOCTYPE HTML>
<html>
<head>
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
function OnLoad() {
var myCounter = 0;
$('.insert').live('click', function() {
var currentRow = $(this).parents("tr:first");
var newRow = currentRow.clone(true);
newRow.children('td:last').empty().append('<input name="myid">');
currentRow.after(newRow);
document.myForm.myid.focus();
});
$('.delete').live('click', function() {
if(confirm("Are you sure?")){
$(this).parents("tr").remove();
}
});
}
google.load("jquery", "1");
google.setOnLoadCallback(OnLoad);
</script>
</head>
<body>
<form name="myForm">
<table border="1">
<tr>
<td class="insert">Add</td>
<td class="delete">Erase</td>
<td>Sample data goes here</td>
</tr>
</table>
</form>
</body>
</html>
換句話說,我不希望他們點擊「添加」,然後再次「添加」。
你應該改變'追加('')'到'append('')'(自閉標籤) – SLaks 2010-02-24 20:16:59