Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/397.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_Css - Fatal编程技术网

Javascript 单击复选框按钮时,禁用所有输入类型值

Javascript 单击复选框按钮时,禁用所有输入类型值,javascript,jquery,css,Javascript,Jquery,Css,在这里,我在我的页面中使用相同的地址选项 当我单击同一地址的复选框时,我的其他输入必须禁用 我的代码: <ul><input type="checkbox" name="same-address" /> Click for same address <br />Enter Address here: <input type="text" name="address" /> Enter City here: <input type="text"

在这里,我在我的页面中使用相同的地址选项 当我单击同一地址的复选框时,我的其他输入必须禁用 我的代码:

<ul><input type="checkbox" name="same-address" /> Click for same address <br />Enter Address here: <input type="text" name="address" /> Enter City here: <input type="text" name="city" /> </ul>
    单击相同地址
    在此处输入地址:在此处输入城市:
您可以使用按类型选择输入,并使用
.prop
更新
输入的
禁用状态

$('input[type="checkbox"]').click(function() {
    $('input[type="text"]').prop('disabled',this.checked);
});

您可以使用
输入选择器
选择所有输入元素,同时使用
道具
禁用控件

 $('input[type="checkbox"]').click(function() {
        $('input[type="text"]').prop('disabled',this.checked);
    })

请尝试使用下面的代码段

<!DOCTYPE html>
<html>
<head> 
<title>Test</title>
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> 
<script>
$( document ).ready(function() {  
      $('.SameAsBillingAddress').on('click',function(){

        if($(this).prop('checked'))
        {
            $('.Address2').prop('disabled', true);
        }
        else
        {
            $('.Address2').prop('disabled', false);
        }
       });

}); 

</script>

</head>
<body>
<div>
<ul>
    <div style="height:30px; width:80%; margin-left:30px; clear:both;">
        <input name="" type="checkbox" value="" class="SameAsBillingAddress" />Same as Billing Address</div>
    <li>
        <label>House No.:</label>
        <input type="text" name="house no" class="Address2" placeholder="House No" />
    </li>
    <li>
        <label>Street:</label>
        <input type="text" name="street" class="Address2" placeholder="Your Street" />
    </li>
    <li>
        <label>City</label>
        <input type="text" name="city" class="Address2" placeholder="Your City" />
    </li>
    <li>
        <label>Zip:</label>
        <input type="text" name="zip" class="Address2" placeholder="Your Zip" />
    </li>
    <li>
        <label>Country:</label>
        <select class="Address2">
            <option>India</option>
        </select>
    </li>
    <li style="float:right;">
        <label></label>
        <input type="submit" name="save" class="Address2" value="Save Details" />
    </li>
</ul>
</div>

</body>
</html>

试验
$(文档).ready(函数(){
$('.SameAsBillingAddress')。在('click',function()上{
if($(this.prop('checked'))
{
$('.Address2').prop('disabled',true);
}
其他的
{
$('.Address2').prop('disabled',false);
}
});
}); 
    与帐单地址相同
  • 门牌号:
  • 街道:
  • 城市
  • 邮编:
  • 国家: 印度
试试这个

    $('#same').click(function () {
    if ($(this).is(':checked')) {
        $(this).parents('ul').find('li input[type="text"],select').attr('disabled', 'disabled');
    } else {
        $(this).parents('ul').find('li input[type="text"],select').removeAttr('disabled')
    }
});

我建议对输入控件进行范围界定。这将禁用页面上的所有文本输入。但是我不想隐藏地址的上方输入类型。你可以用JS FIDDLE解释吗?我可以在这里使用一个id,其中所有输入类型在单击时隐藏,当再次单击时,它工作。我不明白你的意思。你能重新措辞你的问题吗?