简体   繁体   English

jQuery隐藏 <p> 似乎不起作用?

[英]JQuery hide <p> does not seem to work?

Okay... obviously this is because I am so new. 好吧...显然这是因为我很新。 I don't understand why this does not work. 我不明白为什么这行不通。 I thought this is because the argument its not inside a function but I don't really know. 我认为这是因为参数不在函数内,但我并不真正知道。

<head>
    <title>Documento sin título</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">
        $(function(){
            $("p").hide();
        });
    </script>
</head>
<body>
    <p>hi</p>
</body>

It should look like this: 它看起来应该像这样:

<script src="jquery.js"></script>
<script>
    $(function() {
        $('p').hide();
    });
</script>

First you must load the external Javascript file (like jquery.js ) in its own script tags. 首先,您必须在其自己的script标签中加载外部Javascript文件(例如jquery.js )。 Then you include your Javascript (or jQuery for this case) in its own script tags. 然后,将Javascript(在这种情况下为jQuery)包含在自己的script标签中。

Your code works! 您的代码有效!

However, you need to load the JS file first. 但是,您需要先加载JS文件。 The function to hide the p should be in its own <script> tag (different one from loading the script) 隐藏p的函数应该在其自己的<script>标记中(与加载脚本不同)

 $(function() { $("p").hide(); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <p>hi</p> <div>world!</div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM