-1

我在 Dreamweaver 中有一个 image.html 文件。

在源代码中,我链接了一个名为 img.js 的 js 文件

<!doctype html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>PHOTO</title>
        <script language="javascript" type="text/javascript" src="js/img.js"></script>
        </body>
</html>

如果在 img.js 中使用警报

alert("My First Jquery Test");

它在网页中正确显示,但如果编写一些 javascript 代码,例如

<html>
<body>

<p id="p2">Hello World!</p>

<script>
document.getElementById("p2").style.color="blue";
</script>

上面的段落被脚本改变了。

什么都没有显示..为什么以及如何显示这个?

4

2 回答 2

0

做对了

编辑 img.js

window.onload=function(){
    alert("My First Jquery Test");
   document.getElementById("p2").style.color="blue";
}
于 2013-09-30T08:32:32.490 回答
0

正如您在此处看到的那样,该脚本正在运行。如果仍有问题,请报告您的完整 HTML 文件。

记住:

<html>
   <head></head>
   <body>
      <p id="p2">Hello World!</p>

      <script>
         document.getElementById("p2").style.color="blue";
      </script>
   </body>
</html>
于 2013-09-30T07:27:28.743 回答