JS学习笔记1

来源:互联网 发布:搜索不到网络打印机 编辑:程序博客网 时间:2024/05/22 16:40

1.<script>标签可以在<head>,<body>部分,在body部分时遇到就直接解析调用;使用html输出<script>document.write(" this is a script use document.write ");</script>

2.使用button响应点击事件:<button type="button" onclick="alert('welcome to learn js ')">点我</button> 

关于这个标签呢,主要决定标签中间的内容在网页上面显示的样子,比如把button换成text,点击点我,也有提示框的出现(这个取决于onclick响应事件),type这个目前没发现特别有必要

3.点击button执行script里面自定义的函数:

<body> 

<button type="button" onclick="myFunction()" >点我</button>  //点击按钮会调用onclick声明的函数myFunction();

<script >function myFunction()  //使用function声明一个函数

{ document.write("aaa");} //调用这个函数后,会把网页文档刷新为aaa

</script>

</body>

一个网页中可以有多个script标签,一个script标签中可以有多个函数

4.创建一个输入框,点击按钮验证输入的值是不是数字

<body>

<input id="input" type="text">

<button in="b1" type="button" onclick="check()">点我</button>

<script >

var v=document.getElementById("input").value;

if(v==""||isNaN(v)) {

alert("not numeric");

}

</script>

</body>

0 0
原创粉丝点击