JS是运行在客户端的脚本(script)语言
引入JS进html
①sript标签内编写
<script type="text/javascript">
document.write("<h1>hi</h1>")
window.alert("who")
</script>
②外部JS script src【CSS是link href】
<head>
<title>Document</title>
<link type="text/css" rel="2" href="URL.css">
<script src="./ht.js"></script>
</head>
③内联
<body>
<button onclick="javascript:alert('hi')">anniu
</button>
</body>
var i=0;
var arr1=new Array(19);
var str=new String("hi");
var stu={
name:"me",
age:1
}
document.write("写入网页");
window.alert("弹出警告框" );
console.log("控制台输出");
String对象:属性length
Array对象:属性length 方法join() reverse() sort()
Date对象: myDate = new Date()
JS事件
onClick | 点击 |
onChange | 内容改变 |
onFocus | 获得焦点 |
onBlur | 失去焦点 |
onLoad | 载入浏览器 |
onUnload | 离开页面 |
onMouseOver | 鼠标移到对象 |
onMouseOut | 鼠标离开对象 |
onMouseMove | 鼠标在对象上移动 |
onMouseDown | 鼠标在对象上按下 |
onMouseUp | 鼠标在对象上释放 |
onSubmit | 提交表单 |
onResize | 改变窗口大小 |
</head>
<script type="text/javascript">
function hello(){
alert("hi");
}
</script>
<body>
<a href="./html2.html" onmousemove="hello()">link</a>
</body>
windows.alert()警告框
windows.confirm()确认
windows.prompt()提示
document.write()
docunment.getElementById("").value
input类型:text password sumbit、reset、 checkbox(多选)、ratio(单选)
提交表单(<form action="提交到何处" method="get/post")
</head>
<script type="text/javascript">
function hello(){
var name = document.getElementById("username").value;
var password= document.getElementById("psw").value;
alert(name+":"+password);
}
</script>
<body>
<form action="">
name <input type="text" id="username" ><br>
psw <input type="password" id="psw">
<input type="submit" id="sub" onclick="hello()">
</form>
</body>
<textarea cols="" row=""></textarea> 文本域
下拉选框:
<select size="2" multiple="multiple">
<option value="1">3</option>
<option value="2">4</option>
</select>