Javascript隐藏()

Javascript隐藏(),javascript,jquery,html,Javascript,Jquery,Html,我试图使用java脚本隐藏单击按钮。我的代码由于某种原因不起作用,这里是代码。一切正常屏幕上会弹出警报,但隐藏功能不起作用 <html> <head> <title>Hello JQuery world!</title> <script type="text/javascript" src="jquery-1.10.2.min.js"></script> <script type="tex

我试图使用java脚本隐藏单击按钮。我的代码由于某种原因不起作用,这里是代码。一切正常屏幕上会弹出警报,但隐藏功能不起作用

   <html>
   <head>
   <title>Hello JQuery world!</title>
   <script type="text/javascript" src="jquery-1.10.2.min.js"></script>
   <script type="text/javascript" src="script1.js"></script>
   </head>
   <body>
   <table class="data" id="celebs">
<thead>
    <tr>
        <th>ID</th>
        <th>Name</th>
        <th>Occupation</th>
        <th>Approx. Location</th>
        <th>Price</th>
    </tr>
</thead>
<tbody>
    <tr>
        <th>1</th>
        <th>Johnny</th>
        <th>Wrestler</th>
        <th>Knocksville</th>
        <th>500</th>
    </tr>
        <tr>
        <th>2</th>
        <th>Molly</th>
        <th>Pharmacist</th>
        <th>Germany</th>
        <th>1500</th>
    </tr>
    <tr>
        <th>3</th>
        <th>Scooby Doo</th>
        <th>Detective</th>
        <th>Jersey</th>
        <th>Scooby Snacks</th>
    </tr>
    <tr>
        <th>4</th>
        <th>Pacman</th>
        <th>Character</th>
        <th>Area 51</th>
        <th>20</th>
    </tr>
    <tr>
        <th>5</th>
        <th>Ryu</th>
        <th>Street Fighter</th>
        <th>Japan</th>
        <th>1891564</th>
     </tr>
      </tbody>

      </table>
      <input type="button" id="hideButton" value="hide" />
      <input type="button" id="disclaimer" value="hide" />
      </body>
     </html>

在加载文档之前调用事件绑定函数。因此,事件绑定将无法工作。您应该将事件绑定函数放在
(function(){..})
块中

$(function(){
        alert('Welcome');
        alert($('#celebs tbody tr:even').length + ' elements!');
        $('#hideButton').click(function(){
            $('#celebs').hide();
        });
        var fontSize = $('#celebs tbody tr:first').css('font-size');
        alert(fontSize);
        $('#celebs tbody tr:even').css('background-color', '#0C6');
        $('#celebs tbody tr:odd').css({'background-color': '#930', 'color':'#C6F' }
        );
    });

控制台中会出现什么错误?它似乎工作正常:提示:将所有jQuery放在一个
$(function(){…})中块您有两个value=“hide”按钮。您是否单击了正确的(左)按钮?:)对我来说也很好:+1同意。当jsiddle在
中加载jQuery时(就像OP的代码一样),它将。如果您将javascript包装在
(function(){…})
中,它将被删除。
$(function(){
        alert('Welcome');
        alert($('#celebs tbody tr:even').length + ' elements!');
        $('#hideButton').click(function(){
            $('#celebs').hide();
        });
        var fontSize = $('#celebs tbody tr:first').css('font-size');
        alert(fontSize);
        $('#celebs tbody tr:even').css('background-color', '#0C6');
        $('#celebs tbody tr:odd').css({'background-color': '#930', 'color':'#C6F' }
        );
    });