背景是:我有一個可編輯的表格,其中添加了一個新行。我也有與啓動兩個功能:當文檔準備好和文檔更改時應該初始化jquery函數的語法是什麼?
$(函數(){
這些功能讓用戶編輯線路和用戶還可以將滴東西成表,但只有它適用於普通行,而不是最近添加的行,即使它們與所有其他行都具有相同的類。是否可以修改函數以便它們可以用於新添加的行?如果是 - 如何執行?還是另一個問題?
Regards
編輯: 這裏是我的,增加了一個錶行按鈕代碼:
$(function() {
$("#editableTable").on('click', 'input.addButton', function() {
var nexttr = $(this).closest('tr');
$(nexttr).next().before('\n<tr class=\"sortable-row ui-droppable\">\n<td>entry 1</td>\n<td>entry 2</td>\n<td>entry 2</td>\n<td>entry 4</td>\n<td>entry 5</td>\n<td>entry 6 </td>\n<td>entry 7</td>\n<td>entry 8</td>\n<td><input type=\'button\' class=\'addButton\' value=\'add row\' /></td>\n<td><input type=\'button\' class=\'deleteButton\' value=\'delete row\' /></td>\n</tr>\n');
oddRowColor(); //changes color in every second row
});
});
,使TD-元素可編輯的代碼是這樣的:
$(function() {
$("td").dblclick(function() {
var OriginalContent = $(this).text();
$(this).addClass("cellEditing");
$(this).html("<input type='text' id='textinput' size='100' value='" + OriginalContent + "' />");
$(this).children().first().focus();
$(this).children().first().keypress(function (e) {
if (e.which == 13) {
var newContent = $(this).val();
$(this).parent().text(newContent);
$(".cellEditing").removeClass("cellEditing");
}
});
$(this).children().first().blur(function (e) {
$(this).parent().text(OriginalContent);
$(".cellEditing").removeClass("cellEditing");
});
});
});
第一:你應該有文件準備好處理程序('$(函數(){});')只是在你的頁面一次。第二:您可能不使用委託來附加處理程序,因此動態添加的元素將被忽略。第三也是最重要的:向我們顯示您的代碼,以便我們能夠爲您提供幫助。 – melancia
到目前爲止謝謝。我在上面添加了我的代碼。我將在jquery紀錄片中閱讀關於授權方法的內容。 Thx的小費! :) – user2718671