这个例子有什么问题:
$('label#formSecondPhone:first-child').change(function() {
var id = $('#formSecondPhoneField');
$(this).attr('checked') ? $(id).show() : $(id).hide();
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<label id="formSecondPhone"><input type="checkbox" name="secondContact" value="1"> Phone</label>
<label id="formSecondPhoneField" class="form-item">Enter your number: <input type="number" name="secondPhone"></label>
&#13;
formSecondPhoneField未显示/隐藏
答案 0 :(得分:2)
$(':checkbox[name=secondContact]').change(function() {
var id = $('#formSecondPhoneField');
console.log($(this).is(':checked'))
$(this).is(':checked') ? $(id).show() : $(id).hide();
}).change();
#formSecondPhoneField {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label id="formSecondPhone"><input type="checkbox" name="secondContact" value="1"> Phone</label>
<label id="formSecondPhoneField" class="form-item">Enter your number: <input type="number" name="secondPhone"></label>