5、网页制作Dreamweaver(JS的初步运用)

JAVASCRIPT

*放在头部也可以读取(最先读取头部)

表单提交时会自动刷新网页,最好关掉

写法:

1、输出

<script>

                   document.write("hello world");

</script>

2、按钮运用

<input name="alert" value="alert"type="button" onclick=‘alert("这是触发事件")‘/>

 

3、定义变量并输出

    var bianliang;

         bianliang="123";

         document.write(bianliang);

4、改变元素的属性

<p id="hello">hello</p>

<script>

         function hello()

         {

                   x=document.getElementById("hello")

                   x.style.color = "#ff0000";

         }

</script>

<input type="button" value="点击变颜色" onclick="hello()" />

<!--点击由黑色变红色-->

5item索引,指示第n个出现的元素,与getElementsByName同时使用

 

 

定义一组变量

var student =

         {

                   name:"张三",

                   sex:""

         };

         student.name="张三";

         document.write(student.name);

*打印“张三”)

外部调用JS

<script src=””></script>

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。