用于启用表单字段的单选按钮 [英] radio button to enable form fields

查看:72
本文介绍了用于启用表单字段的单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两个单选按钮的表单,我想在选中单选按钮时启用相应的字段。我的代码不起作用,这里是:

I have a form containing two radio buttons, I want to enable corresponding fields when a radio button is checked. My code just isn't working, here it is:

<head>
<script type="text/javascript" src="jquery.js"></script>          
<script type="text/javascript">
$(document).ready(function() {

    var $type = $('select'),
        $field1 = $("#fieldID1"),
        $field2 = $("#fieldID2");

    $type.change(function() {

        var isDisabled = ($type.filter(":checked").val() === "1");

        $field1.prop("disabled", !isDisabled);
        $field2.prop("disabled", isDisabled);

    }).change();
});
</script>
</head>

我的html正文如下:

My html body is like:

<body>

<form action="" method="post">

<input type="radio" name="select" value="1" />
<input type="text" name="fieldID1" id="fieldID1"/>

<input type="radio" name="select" value="2" />
<table id="fieldID2">
    <tr>...</tr>
    <tr>...</tr>
    ...
</table>

<input type="submit" value="Add">
</form>
</body>

我引用了这篇文章。任何人都可以指出我的问题是什么,我对jQuery不太熟悉,谢谢!

I referenced the code from this post. Can anyone point me out what the problem is, I am not quite familiar with jQuery, thanks!

仍然无法修复...

推荐答案

    $fieldID1.prop("disabled", !isDisabled);
    $fieldID2.prop("disabled", isDisabled);

应该是:

    $field1.prop("disabled", !isDisabled);
    $field2.prop("disabled", isDisabled);

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

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