2013-11-22 71 views
-1

HTML代码:Enabiling文本框与编辑按钮并更新新的文本

<table width="50%" align="center" border="0" class="check-table" cellspacing="1" cellpadding="5"> 
    <tr> 
     <th width="11%"><input type="checkbox" class="checkall" /></th> 
     <th width="44%">Product Name</th> 
     <th width="24%">Quantity<br /></th> 
     <th width="21%">Action</th> 
    </tr> 
    <tr> 
     <td align="center"><input type="checkbox" /></td> 
     <td align="center"><input type="text" value="Produt One" disabled="disabled" /></td> 
     <td align="center"><input type="text" value="" disabled="disabled" /></td> 
     <td align="center"><a href="#">Edit</a> | <a href="#">Delete</a></td> 
    </tr> 
    <tr> 
     <td align="center"><input type="checkbox" /></td> 
     <td align="center"><input type="text" disabled="disabled" value="Product Two" /></td> 
     <td align="center"><input type="text" value="" disabled="disabled" /></td> 
     <td align="center"><a href="#">Edit</a> | <a href="#">Delete</a></td> 
    </tr> 
</table> 

jQuery代码:

$(function(){ 
    $('.checkall').on('click', function(){ 
     $(this).closest('.check-table').find(':checkbox').prop('checked',this.checked); 
    }) 

    $(".check-table tr td:nth-child(4) a:last-child").on("click", function() { 
     $(this).closest(".check-table tr").remove(); 
    }); 

    $('.check-table tr td:nth-child(4) a:first-child').on('click', function(){ 
     $(this).add(".check-table tr td:nth-child(2) input[type=text], .check-table tr td:nth-child(3) input[type=text]").prop('disabled',false); 
    }) 
}) 
+0

任何人可以帮助? – DhiruSingh

+1

您的要求是什么? – FBHY

+0

当我点击编辑按钮时,所有文本框都启用了,我只想要启用一个特定的行文本框。 http://jsfiddle.net/DhiruSingh/5u8Gh/2/ – DhiruSingh

回答

0

我相依为命编辑链接类编辑

<td align="center"><a href="#" class="edit">Edit</a> | <a href="#">Delete</a></td> 

然后对于js部分:

$('body').on('click','.edit', function(){ 
    $(this).parents('tr').find('input').attr('disabled',false); 
}); 

http://jsfiddle.net/8LR9R/


关于你的第二resquest,你可以做这样的事情:

$('body').on('click','.edit', function(){ 
    if($(this).hasClass('on')){ 
     disabled = true; 
     str = 'Edit'; 
     $(this).removeClass('on'); 
    }else{ 
     disabled = false; 
     str = 'Save'; 
     $(this).addClass('on'); 
    } 
    $(this).parents('tr').find('input').attr('disabled',disabled); 
    $(this).text(str); 
}); 

http://jsfiddle.net/8LR9R/3/

+0

很棒:)非常感谢你。 .. 我有一个更多的点击后,点击“编辑”后,我们可以隐藏编辑和点击“保存”后显示“保存”,我们可以禁用文本框。 – DhiruSingh

+0

检查我的编辑:) – FBHY

+0

非常感谢你,这是伟大的.. :)这对我非常有帮助。 – DhiruSingh