我有一個演示在這裏我的問題:http://codepen.io/anon/pen/rOzQaj如何保存每個輸入值?
$(document).ready(function(){
$('.del').on('click', function(){
$(this).closest('tr').fadeOut(450);
if ($('.read_content').is(':visible')) {
$('.read_content').fadeOut(1000);
};
});
$('.read').on('click', function(){
$('.read_content').toggle();
$('.name').html($(this).closest('tr').find('.user_name').html());
$('.email').html($(this).closest('tr').find('.user_email').html());
$('.phone').html($(this).closest('tr').find('.user_phone').html());
});
$('.edit').on('click', function(){
$(this).closest('tr').find('td:lt(3)').toggleClass('ready');
if ($(this).closest('tr').find('td:lt(3)').hasClass('ready')) {
$(this).html('Save');
$(this).closest('tr').find('td:lt(3)').html('').append('<input class="vals" type="text">');
}
else{
$(this).closest('tr').find('td:lt(3)').html($('.vals').val());
$(this).html('Edit').removeClass('ready');
}
});
});
什麼我真的要做的是,當我點擊編輯(文本更改保存)按鈕,每個TD元素的文字將被更改爲輸入所以它可以編輯每個字段(名稱,電子郵件,電話),當我再次點擊保存時,字段被更改,但只有第一個字段的文本,所以我如何使它保存每個不同的數據領域?
例如現在如果你鍵入
名:V
電子郵件:[email protected]
電話:32323
,當你點擊保存的所有字段將變更爲V,而不是不同的所有電子郵件和電話字段的數據。
做得好我正要建議OP使用id屬性爲每個字段並單獨檢索 –
「編輯「按鈕不能保持以前的值 – Aroniaina
@Aroniaina:我不這麼認爲,它在由OP提供的原始筆或 –