2012-03-30 115 views
1

我有以下的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(); 
}); 
}); 

回答

2

解決的辦法是:

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

非常感謝。有時我會在不受歡迎的語法 – lgt 2012-03-30 08:20:38

+0

之間鬆懈,它偶爾會發生在我們所有人身上:) – 2012-03-30 08:21:15

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

}); 
相關問題