为什么我不能使用jQuery功能 [英] Why I cant use jQuery functionality

查看:84
本文介绍了为什么我不能使用jQuery功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 / opt / lampp / htdocs 目录中有 jquery-2.1.3.js 库,并将测试它我将其包含在一个html文件中

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>

从此我预计会更改< / p> / code>标签为橙色,并将< / body> 背景设置为绿色,但我所得到的只是简单的输出: 在默认颜色和默认背景下。为什么这不工作?

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?

推荐答案

脚本元素可以有一个 src 属性内容,但不能同时包含两者。如果他们有两个内容,内容将被忽略(内容被视为脚本文档,而不是代码)。

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).

为jQuery脚本使用另一个脚本块

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>

这篇关于为什么我不能使用jQuery功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆