开发者

jquery add/remove with greyout option

How can I undo the grey-out if the select row was removed? Also, when there are sev开发者_JAVA技巧eral rows added, I want to remove only the row corresponding to that "Remove" button and not the others. I guess, my main concern is how can I know which added row has been removed, when the "remove" button is clicked. Please help. Many thanks in advance.

$('#btn').live('click',function() {
   $("#table_name tr:first").before("<tr><td class='c'><input type='hidden' name='a_name' value='" + a + "'>" + a + "</td><input type='button' class='delete' value='Remove'></td></tr>");
   $("#a option:selected").attr("disabled", true);
});
$('#table_name td .delete').live('click',function(){
   // here I want to once again enable the selection
   attr("disabled", false);
   $(this).parent().parent().remove();
});
<select id="a" name="a">
   <option value="1">1</option>
   <option value="2">2</option>
   <option value="3">3</option>
   <option value="4">4</option>
</select>
<input id="btn" class="button" type="button" value="Add" />


Replace this:

// here I want to once again enable the selection
   attr("disabled", false);

With something like:

// Grab the value of the corresponding input
var val = $(this).prev('td').find('input[name=a_name]').val();
// Re-enable the corresponding select option
$('select#a option[value='+val+']').removeAttr('disabled');

You have to use the value from the hidden input to relate it with the select option element.


perhaps

$(...).removeAttr("disabled");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜