0

私の問題は次のとおりです。いくつかのコードを見つけました。私が言ったことを実行するにはどうすればよいですか?そして、誰かがメニュー項目をクリックしたときに、チェックボックスの値を削除したい(チェックされていない) 私のコードは次のとおりです:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript"> 

$(function(){
    $(".form-row").hide();

       $("#divListBox").find(":checked").each(function() {
   $(this).removeAttr("checked");
});


       $("#course_english").change(function() {
         if ($("#course_english").val() == "MA English") {
             $(".form-row").show();
         } else {
            $(".form-row").hide();
         }
    });
 });
</script>
</head>
<body>
<select id="course_english" class="" name="course_english"> 
    <option value="">--Select One--</option> 
    <option value="MA English">MA English</option> 
    <option value="B. A. (Hons.) with Mass Communication">B.A. (Hons.) with Mass Communication</option> 
    <option value="M. A. (English)">M. A. (English)</option> <option value="M. Phil.">M. Phil.</option> 
</select>


  <div class="form-row" id="divListBox">
    <label for="sem_1_ma_english-poetry">
      <input id="sem_1_ma_english-poetry" class="sem_1_ma_english" type="checkbox"      value="Poetry" name="sem_1_ma_english[]">
Poetry
 </label>
 <label for="sem_1_ma_english-drama">
  <input id="sem_1_ma_english-drama" class="sem_1_ma_english" type="checkbox"     value="Drama"  name="sem_1_ma_english[]">
Drama
</label>
 <label for="sem_1_ma_english-fiction">
  <input id="sem_1_ma_english-fiction" class="sem_1_ma_english" 
   type="checkbox" value="Fiction" name="sem_1_ma_english[]">
  Fiction
 </label>
 <label for="sem_1_ma_english-prose">
 <input id="sem_1_ma_english-prose" class="sem_1_ma_english" type="checkbox"      value="Prose" name="sem_1_ma_english[]">
 Prose
</label></div>
</body>
</html>
4

2 に答える 2

0

試す:

   $("#course_english").change(function() {
     if ($("#course_english").val() == "MA English") {
         $(".form-row").show();
     } else {
        $(".form-row").hide();
     }
    $("#divListBox").find(":checked").each(function() {
        $(this).prop("checked", false);
    });
});
于 2012-12-06T01:27:40.647 に答える
0

入れてみてください:

$("#divListBox").find(":checked").each(function() {
   $(this).removeAttr("checked");
});

$("#course_english").change() 内で、選択値が変更されたときに各ボックスのチェックを外します。

最終的な js は次のようになります。

$(function(){
    $(".form-row").hide();




       $("#course_english").change(function() {
         $("#divListBox").find(":checked").each(function() {
           $(this).removeAttr("checked");
         });

         if ($("#course_english").val() == "MA English") {
             $(".form-row").show();
         } else {
            $(".form-row").hide();
         }

    });
 });

デモはこちら

于 2012-12-06T01:40:20.747 に答える