如果未选中此复选框,则jQuery清除输入字段 [英] jquery clear input fields if the checkbox is unchecked
本文介绍了如果未选中此复选框,则jQuery清除输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下jquery,如果选中此复选框,则可以让用户填写表单中的其他字段.我要清除的是如果未选中此复选框,则其他输入字段的值.
I have the following jquery, what is letting the user to fill out additional fields in the form if the check box is checked. What I want is to clear the additional inputs fields values if the check box is unchecked.
$(document).ready(function() {
$('input:checkbox').attr('checked', false);
$('#xml').hide();
$('#checkbox').click(function() {
$('#xml')[this.checked ? "show" : "hide"]();
});
$('input[type="checkbox"]').click(function() {
if (this.checked) {
$('div#xml p label input').attr('required', true);
}
else
$('div#xml p label input').removeAttr('required', true);
//Here should the corresponding code to be pasted
//$('div#xml p label input').val = ('');
});
$(function() {
$("#datepicker").datepicker();
});
});
推荐答案
解决方案是:
$('div#xml p label input').val("");
这篇关于如果未选中此复选框,则jQuery清除输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文