如果使用 jquery 检查单选按钮,则启用输入字段 [英] enable input fields if radio buttons is checked with jquery
本文介绍了如果使用 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">
我希望如果用户单击单选按钮中的选项 Yes,请将 html 属性disabled="disabled"
删除到最后一个输入字段,如果用户单击在单选按钮中的选项 No 中,将属性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
这篇关于如果使用 jquery 检查单选按钮,则启用输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文