如果复选框未选中,jquery将清除输入字段
我有下面的jquery,如果选中复选框,用户可以填写表单中的其他字段。我想要的是,如果复选框未选中,则清除其他输入字段值如果复选框未选中,jquery将清除输入字段,jquery,Jquery,我有下面的jquery,如果选中复选框,用户可以填写表单中的其他字段。我想要的是,如果复选框未选中,则清除其他输入字段值 $(document).ready(function() { $('input:checkbox').attr('checked', false); $('#xml').hide(); $('#checkbox').click(function() { $('#xml')[this.checked ? "show" : "hide"](
$(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("");
你应该这样做
$('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);
$('div#xml p label input').val('');
}
});
另一个工作解决方案:
<script type="text/javascript">
$(document).ready(function(){
$('#pizzaOption>input[type="checkbox"]').click(function() {
if ($(this).is(':checked')) {
var pizzaPrice=$(this).closest("#pizzaOption").data('price');
console.log(price);
$('#total').html(pizzaPrice);
} else {
var pizzaPrice=0;
$('#total').html(pizzaPrice);
}
});
});
</script>
$(文档).ready(函数(){
$('#pizzaOption>input[type=“checkbox”]”)。单击(函数(){
如果($(this).is(':checked')){
var pizzaPrice=$(此).closest(#pizzaOption”).data('price');
控制台日志(价格);
$('#total').html(比萨饼价格);
}否则{
var pizzaPrice=0;
$('#total').html(比萨饼价格);
}
});
});