为什么js放在html页面中起作用,单独放到js页面调用就不起作用呢?

JavaScript09

为什么js放在html页面中起作用,单独放到js页面调用就不起作用呢?,第1张

js放在html页面中起作用,单独放到js页面调用就不起作用是设置错误造成的,解决方法为:

1、新建html文档。

2、准备好需要用到的图标。

3、书写hmtl代码。<center><a id="J_LinkBuy" class="buy-btn" href="#">立即购买</a></center>。

4、书写css代码。body { height: 3000pxmargin: 0padding: 0background: #E1FFEC}.buy-btn { display: blockwidth: 127pxheight: 36pxoutline: noneoverflow: hiddenmargin: 10px auto 0text-indent: -999pxbackground: url(../images/gm.png) 0 0}。

5、书写并添加js代码。

6、查看效果。

需要准备的材料分别有:电脑、html编辑器、浏览器。

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、在index.html中的<script>标签,输入js代码:var a = '<input type="text" value="test" />'document.body.innerText = a。

3、浏览器运行index.html页面,此时html代码被当成字符串渲染到了页面上。

js输出html中表格的方法如下:

document.write("<table border=1 >")

for(i=1i<=ri++)

{

document.write("<tr>")

for(j=1j<=cj++)

document.write("<td>"+Math.pow(j,i))  //输出数组

document.write("</tr>")

}

document.write("</table>")

运行结果: