如果使用jquery选中了单选按钮,则启用输入字段 [英] enable input fields if radio buttons is checked with jquery

查看:80
本文介绍了如果使用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

这篇关于如果使用jquery选中了单选按钮,则启用输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆