作业
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
function arrays()
{
var arr = ['a','b','c'];
var arr2 = ['aa','b','c'];
for(var i=0;i<arr2.length;i++){
arr.push(arr2[i]);
}
//往数组尾部添加一个数组
arr.push('e');
console.log(arr);
//从数组尾部弹出一个元素
var res = arr.pop();
console.log(res);
console.log(arr);
}
//从数组头部住家元素
function arrays2()
{
//从数组头部住家元素
/* var arr = ['a','b','d'];
arr.unshift('e');
console.log(arr);*/
var arr1 = ['a','b','c','d'];
var res = arr1.shift();
console.log(res);
//删除下表 1,2 的元素
var arr2 = ['a','b','c','d'];
arr2.splice(1,2);
console.log(arr2);
// 修改元素
var arr4 = ['a','b','c','d'];
arr4[1] = 'bb';
console.log(arr4);
//在数组中查到的下表 indexOf 方法 如果操查不到就是-1
var arr6 = ['a','b','c','d'];
var res1 = arr6.indexOf('c');
var res2 = arr6.indexOf('d',2);
console.log(res1);
console.log(res2);
}
//从中机插入数组元素
function arrs(t,val)
{
var arr = ['a','b','c','d','e'];
var res = [];
for (var i=0;i<arr.length;i++){
if(i==t){
res.push(val);
}
res.push(arr[i]);
}
console.log(res);
}
arrs(2,'k');
</script>
</body>
</html>
demo1.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
div{margin: 10px;}
</style>
</head>
<body>
<div><input type="text" id="username" placeholder="请输入用户名"></div>
<div><input type="text" id="pwd" placeholder="请输入密码"></div>
<!--<button herf="javascript" onclick="submits()">提交</button>-->
<div id="mydiv" onmouseover="aa()" onmouseleave ="bb()">我的故事</div>
<div>
<select id="proivnce" onchange="dd()">
<option value="1">安徽</option>
<option value="2">北京</option>
<option value="3">山东</option>
<option value="4">安徽</option>
</select>
</div>
<script type="text/javascript">
function dd(){
var val=document.getElementById('proivnce').value;
alert('当前选择的是:' +val);
}
function aa() {
// console.log('来了');
document.getElementById('mydiv').style.color='red';
}
function bb(){
// console.log('走了');
document.getElementById('mydiv').style.color='black';
}
function submits()
{
var username = document.getElementById('username').value;
var pwd = document.getElementById('pwd').value;
if(username =='')
{
alert('请输入用户名');
return;
}
if(pwd ==''){
alert('请输入密码');
return;
}
alert('用户名:' +username+'密码:'+pwd);
}
</script>
</body>
</html>
总结
1、四个常用数组元素,arr.push增加、 unshift从头部追加、splice删除、pop弹出一个元素、indexOf查找方法
2、window.location.href = ; 直接跳转地址
3、onmouseover=”aa()” onmouseleave =”bb() 设置的特效