如果未选中该复选框,则jquery清除输入字段

时间:2012-03-30 08:13:35

标签: jquery

我有以下jquery,如果选中复选框,则允许用户填写表单中的其他字段。如果取消选中该复选框,我想要清除其他输入字段值。

$(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();
});
});

3 个答案:

答案 0 :(得分:3)

解决方案是:

 $('div#xml p label input').val("");

答案 1 :(得分:0)

你应该做

$('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('');
    }

});

答案 2 :(得分:0)

另一种可行的解决方案:

routes:[
   {
     path: "customer1",
     loadChildren: () => CustomerModule
   },
   {
     path: "customer2",
     loadChildren: () => CustomerModule
   },
    ..etc..
]
相关问题