Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
138 views
in Technique[技术] by (71.8m points)

javascript - Why I cant use jQuery functionality

I have jquery-2.1.3.js library in the /opt/lampp/htdocs directory and to test it I included it in a html file

<html>
    <body>
        <p>Some paragraph</p>
        <script src="jquery-2.1.3.js">
            $("p").css("color","orange")
            $("body").css("background","#00ff00")
        </script>
   </body>
</html>

From this I expected to change all text within </p> tags to orange and set the </body> background to green but I all I get is simple output : Some paragraph in default color and default background. Why this dont work?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

script elements can have a src attribute or content, but not both. If they have both, the content is ignored (the content is considered "script documentation," not code).

Use another script block for your jQuery script

<script src="jquery-2.1.3.js">
</script>
<script>
    $("p").css("color","orange")
    $("body").css("background","#00ff00")
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...