Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.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
Jquery 取消选中复选框时隐藏特定输入类型_Jquery_Checkbox_Input_Textfield_Show Hide - Fatal编程技术网

Jquery 取消选中复选框时隐藏特定输入类型

Jquery 取消选中复选框时隐藏特定输入类型,jquery,checkbox,input,textfield,show-hide,Jquery,Checkbox,Input,Textfield,Show Hide,我有个问题。当复选框被取消选中时,我只想在下面给定的代码中显示全名。当复选框被选中时,它应该显示表单中给定的所有输入类型。下面我有一个代码,它有点反向。当选中时,它隐藏,当不选中时,所有显示。你能帮我这个吗?我的代码是 <html> <body> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script&

我有个问题。当复选框被取消选中时,我只想在下面给定的代码中显示全名。当复选框被选中时,它应该显示表单中给定的所有输入类型。下面我有一个代码,它有点反向。当选中时,它隐藏,当不选中时,所有显示。你能帮我这个吗?我的代码是

<html>
<body>
<head>
<script     src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<form id='sample' action='sample.php' method='post'>

<input type='hidden' name='submitted' id='submitted' value='1'/><br>
<label for='name' >Your Full Name*: </label>
<input type='text' name='name' id='name' maxlength="50" /><br>
<label for='email' >Email Address*:</label>
<input type='text' name='email' id='email' maxlength="50" /><br>

<label for='username' >UserName*:</label>
<input type='text' name='username' id='username' maxlength="50" /><br>

<label for='password' >Password*:</label>
<input type='password' name='password' id='password' maxlength="50" /><br>
<input type="checkbox" name="cb" value="cb"> Hide all!<br>
<input type='submit' name='Submit' value='Submit' />

</form>


<script>
$(function(){

$('input[name=vehicle]').on('change', function(){

if(this.checked){
 $('#sample').find('input').not(this).hide();
   }
  else{
  $('#sample').find('input').not(this).show();
}

})

})





</script>
<script>
 $('input[type="checkbox"]').change(function() {
  var shouldHide = !$(this).is(':checked');
   // Hide all except
   $(this).siblings('label, input').toggle(shouldHide);
 });
</script>

</body>
</html>


您的全名*:
电邮地址*:
用户名*:
密码*:
藏起来
$(函数(){ $('input[name=vehicle]')。在('change',function()上{ 如果(选中此项){ $('#sample').find('input').not(this.hide(); } 否则{ $('#sample').find('input').not(this.show(); } }) }) $('input[type=“checkbox”]”)。更改(函数(){ 变量shoulhide=!$(this).is(“:checked”); //隐藏所有,除了 $(this).sides('label,input').toggle(shoulhide); });
您可以将侦听器更改为:

$('input[type="checkbox"]').change(function(){
    $(this).siblings('label').not(':first').toggle();
    $(this).siblings('input[type=text], input[type=password]').not(':first').toggle()
 }).change();
并将复选框标签稍微更改为

<input type="checkbox" name="cb" value="cb"> Show all!<br>
全部显示
有道理