js两种存在形式
1:文件
2:块
放到body标签底部 防止加载js超时页面反应慢的问题

声明变量
name = "sb"; //全局变量
var age=18; //局部变量

字符串
var name = "alex"
name.charAt(1) //获取第一个元素
name.substring(0,3) //切片
name.indexOf('a') //获取'a'的下标
name.length //获取name长度

数组 字典
var li= [11,22,33] //var li = Array('11,22,33') 创建效果一样
li.push(44) //往后插入44
li.unshift(00) //往前插入00
li.splice(1,0,'sb') //往指定位置(下标为1)插入'sb' 中间元素必须是0
li.pop() //从后面移除一个
li.shif() //前边移除一个
li.splice(1,2) //从第一个下标拿走两个,2指的是个数
li.slice() //切片拿
concat //合并 n=['test'] m=li.concat(n)
li.reverse() //反转

var dic = {'k1':'v1'}


序列化反序列化
JSON.stringify(dic) //序列化
JSON.parse(s) //反序列化

循环语句(列表两种for循环,字典一种)
li = [11,22,33,44];
for (var item in li){
console.log(item,li[item]);
} //循环出来的是li列表的下标或字典的key

for (var i=0;i<li.length;i++){
console.log(i,li[i])
}


异常处理
try{

}catch(e){

}finally{

}


函数
普通函数
function func1(arg){
console.log(arg);
return "sb";
}
var ret = func1(123);
console.log(ret);
匿名函数
自执行函数
(function(arg){
console.log(111,arg); })('SB');
面向对象
http://www.cnblogs.com/wupeiqi/articles/5369773.html


第二篇:Dom
document
1查找元素 基本的有三个
tags = document.getElementsByTagName('h1'); //通过tag找
document.getElementById //通过Id找
document.getElementsByClassName //通过class找

document.getElementsByName(username) //通过name获取,用于input标签
2操作元素
tags[0].innerText = '123'


innerText 对div中间的内容的值进行获取修改用




例子:按钮,数字自加
<body>
<div>
<div ,1000);
function Func(){
var text = document.title;
var firstChar = text.charAt(0);
var subText = text.substring(1,text.length);
var newTitle = subText + firstChar;
document.title = newTitle
}
</script>
</body>




http://www.cnblogs.com/wupeiqi/articles/5369773.html

相关文章:

  • 2022-01-08
  • 2021-06-25
  • 2022-12-23
  • 2021-09-09
  • 2021-08-15
猜你喜欢
  • 2021-10-30
  • 2022-03-08
  • 2021-05-06
  • 2021-07-04
  • 2021-06-02
  • 2021-11-23
相关资源
相似解决方案