2010-12-23 40 views
1

此表在循環中。這是行數是動態的。在jQuery和動態ID問題中編輯一行?

<tr id="data"> 
    <td><input name="cb" type="checkbox" value="val"></td> 
    <td>var 1</td> 
    <td>var 2</td> 
    <td>var 3</td> 
</tr> 

一個編輯按鈕:

<input type="submit" value="edit" id="edit"> 

每一行都有一個複選框。點擊複選框後,整行應該處於編輯模式。我嘗試了很多方法,但仍然遠離結果。我面臨的第二個問題是ID問題。由於該行是動態的,所以......

+0

這個問題需要更多的信息 - 你如何啓用編輯模式?操作是AJAX操作嗎?您發佈修改後的數據的網址是什麼? – 2010-12-23 11:01:00

回答

0

你說

此表是在循環...

但你也有

<tr id="data"> 

idmust be unique within the document ,所以你必須修改它不使用id s。

但是,您不需要在每一行上都有一個id。你可以這樣做:

$('selector_for_the_table tr input[type=checkbox]').change(function() { 

    var row = $(this).closest('tr'); 
    if (this.checked) { 
     // make the row editable 
    } 
    else { 
     // make the row uneditable 
    } 
}); 

Live example

+0

我知道。但如何解決這個問題是我的問題。 – 2010-12-23 11:04:08

+0

@ j-lover:剛剛添加了更新 – 2010-12-23 11:05:15

-1
$("input[name=checkbox_name").bind('onchange',function(){ 
$(this).parent('tr').html();//This line fetch current tr to edit 
});