HTML复选框不起作用

use*_*032 1 html javascript jquery

我想使用复选框显示和隐藏表格.该表出现并消失,没有任何问题.但是没有检查复选框.我有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>
Run Code Online (Sandbox Code Playgroud)

Moh*_*dil 5

试试这种方式 -

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

工作演示--> http://jsfiddle.net/pmNAe/