Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Javascript启用基于输入表单类型的复选框输入_Javascript_Jquery_Html - Fatal编程技术网

使用Javascript启用基于输入表单类型的复选框输入

使用Javascript启用基于输入表单类型的复选框输入,javascript,jquery,html,Javascript,Jquery,Html,我正在尝试使用Java脚本根据选中或取消选中来启用或禁用输入类型 我正在使用以下代码 <script language="JavaScript"> <!-- function enable_text(status) { status=!status; document.f1.other_text.disabled = status; } //--> </script> <body onload="enable_text(false)";>

我正在尝试使用Java脚本根据选中或取消选中来启用或禁用输入类型

我正在使用以下代码

<script language="JavaScript">
<!--

function enable_text(status)
{
status=!status; 
document.f1.other_text.disabled = status;
}
//-->
</script>


<body onload="enable_text(false)";>

<form name="f1" method="post">
<input type="checkbox"  onclick="enable_text(this.checked)" ><br>
Name
<input type="text" name="other_text">
</form>

</body>


名称
但现在我的要求是每个输入类型都有相应的复选框

如果我选中一个复选框,则应仅激活相应的输入

有人能帮上忙吗。

你可以这样做

<script language="JavaScript">
<!--

function enable_text(status,inputName)
{
if(!inputName) {
    var inputs = document.f1.getElementsByTagName('input');
    for(var i in inputs) {
        var input = inputs[i];
        if(input.type == 'text')
            input.disabled = true;
    }
    return;
}
status=!status; 
document.f1[inputName].disabled = status;

}
//-->
</script>


<body onload="enable_text(false)";>

<form name="f1" method="post">
<input type="checkbox"  onclick="enable_text(this.checked,'other_text')" ><br>


 Name
    <input type="text" name="other_text">
 <input type="checkbox"  onclick="enable_text(this.checked,'other_text1')" ><br>
    Name
    <input type="text" name="other_text1">
    </form>

    </body>


名称
名称
看起来不错。但它只适用于输入类型的文本。您能帮我激活其他输入吗?更改此input.type=='text'以在加载时处理其他类型,如['text','select']。indexOf(input.type)>-1但加载时显示Enable。一旦我们检查并取消选中它,它将显示Disable.Happy to help:)。仍然有任何问题。:-)实际上,这里的要求是我们有大约20个输入输入到全球数据库中。但有些人可能没有所有的数据可以输入。因此,首先我们必须显示哪些是我们可以输入的所有字段,然后让他们选择哪些是他们可以输入的所有字段,一旦他们选择了选项&give continue,那么我们应该让他们选择在上一页中选择的字段。