1

チェックボックスを使用してテーブルを表示および非表示にしたい。テーブルは問題なく表示および非表示になります。しかし、チェックボックスはチェックされていません。私は Jquery v1.8.2 を持っています。私は次のコードを持っています:

<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>
4

5 に答える 5

2

試す

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

デモ:フィドル

于 2013-05-17T11:36:45.770 に答える
0

このJSFIDDLEを試してください

注:クリックの代わりに変更を使用できますが、変更はFirefoxでぼかした後にのみ発生します。

$(function(){

    $('#checkbox').click(function (){
           if(this.checked){
               $("#table").show(); 
          }else{
               $("#table").hide();  
         }
     });
});
于 2013-05-17T11:33:26.543 に答える