2013-05-17 6 views
1

Я хочу отображать и скрывать таблицу, используя флажок. Таблица появляется и исчезает без проблем. Но флажок не проверяется. У меня Jquery v1.8.2. У меня есть следующий код:HTML флажок не работает

<html> 
<head> 
    <title></title> 
    <script type="text/javascript" src="jquery.js"></script> 
    <script type="text/javascript"> 
     $('#checkbox').toggle(function() { 
      document.getElementById('table').style.display = "inline"; 
     }, function() { 
      document.getElementById('table').style.display = "none"; 
     }); 
    </script> 
</head> 
<body> 
    <form action="" method="POST" enctype="multipart/form-data"> 
    <input type="checkbox" id="checkbox"> 
    <br /> 
    <table id="table" style="display: none;"> 
     <tr> 
      <td> 
       <input type="file" name="file"> 
       <input type="submit" name="upload" value="upload"> 
      </td> 
     </tr> 
    </table> 
    </form> 
</body> 
</html> 

ответ

5

Попробуйте этот путь -

$('#checkbox').change(function() { 
    if ($(this).is(":checked")) { 
     $('#table').show(); 
    } else { 
     $('#table').hide(); 
    } 
}); 

Работа демо -->http://jsfiddle.net/pmNAe/

+0

thanks..its рабочих – user1763032

+0

Вас! –

0

Тест JSFIDDLE

Примечание: Вы можете использовать изменение вместо щелчка, но, но изменить уволят только после размытия в светлячок.

$(function(){ 

    $('#checkbox').click(function(){ 
      if(this.checked){ 
       $("#table").show(); 
      }else{ 
       $("#table").hide(); 
     } 
    }); 
}); 
0

Вы можете попробовать как

$('#checkbox').click( 
    var my_dis = document.getElementById('table').style.display; 
    if(my_dis == 'inline') 
     document.getElementById('table').style.display = "none"; 
    else //if(my_dis == 'none') 
     document.getElementById('table').style.display = "inline";  
); 
2

Try

$('#checkbox').click(function() { 
    if (this.checked) { 
     $('#table').show(); 
    } else { 
     $('#table').hide(); 
    } 
}); 

Демо: Fiddle

0

Проверьте решение в этой скрипкой:

JSFiddle

$('#checkbox').change(function(){ 
    var $this = $(this); 
    var $table = $("#table"); 

    if($this.is(":checked")) 
     $table.show(); 
    else 
     $table.hide(); 
}); 
Смежные вопросы