如果使用jquery选中了单选按钮,则启用输入字段

问题描述:

我在html代码中有此单选按钮:

I have this radio buttons in html code:

<span><input type="radio" value="false" name="item[shipping]" id="item_shipping_false" checked="checked"><label for="item_shipping_false" class="collection_radio_buttons">No</label></span>

<span><input type="radio" value="true" name="item[shipping]" id="item_shipping_true"><label for="item_shipping_true" class="collection_radio_buttons">Yes</label></span>

我有1个禁用字段,例如:

and I have 1 disabled field like:

<input id="item_shipping_cost" class="currency optional" type="text" size="30" name="item[shipping_cost]" disabled="disabled">

我希望如果用户单击单选按钮中的选项,则将html属性disabled="disabled"删除到最后一个输入字段,并且如果用户单击选项 >在单选按钮中,将属性disabled="disabled"添加到最后一个输入字段

I want that if an user click in option Yes in radio buttons, remove the html attributedisabled="disabled" to this last input field, and if user click in option No in radio buttons add the attributedisabled="disabled" to this last input field

如何使用jquery?

谢谢!

,您可以使用 removeAttr

   $('#item_shipping_true').click(function()
{
  $('#item_shipping_cost').removeAttr("disabled");
});

$('#item_shipping_false').click(function()
{
  $('#item_shipping_cost').attr("disabled","disabled");
});

请参见 JsFiddle