惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
雷峰网
雷峰网
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
人人都是产品经理
人人都是产品经理
博客园 - 【当耐特】
量子位
有赞技术团队
有赞技术团队
博客园 - 三生石上(FineUI控件)
博客园 - Franky
M
MIT News - Artificial intelligence
U
Unit 42
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
The Cloudflare Blog
J
Java Code Geeks
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
MyScale Blog
MyScale Blog
T
Tailwind CSS Blog
T
The Blog of Author Tim Ferriss
V
V2EX

博客园 - Ghost_zhao

knowlegecube 不停服更新二进制文件 linux 热替换so文件 博客更换至 www.zhaoch.top linux ptheard 生产者消费者 一个简单的makefile,一次性编译本文件夹下所有的cpp文件 c++ 最短路两种算法 C++语言十进制数,CDecimal(未完成) C语言面向对象的简便方法 C语言2048 C图书借还示例 MFC小备忘 C++学习备忘(二) C++坦克大战 C++ 走迷宫 MFC 扫雷 C++学习备忘(一) 用MFC作的俄罗斯方块 C#手动回收内存的简单方法
Javascript 备忘
Ghost_zhao · 2013-07-12 · via 博客园 - Ghost_zhao

1遍历所有属性

var person={fname:"John",lname:"Doe",age:25};

for (x in person)
{
  txt=txt + person[x];
}

2.array 有 lenth 属性

var arr = new Array();
var len = arr.lenth;

3 === 类型也相同

4 访问属性的两种方法

objectName.propertyName
objectName["propertyName"]

5 支持 try catch throw

6 isNaN(x) 判断是否数字

7 当你有一个对象的多个属性或者方法需要操作时,就可以使用with

var o=document.createElement("div");
with(o){ style.cursor="pointer"; style.zIndex="100"; innerHTML="aaaa";}
document.body.appendChild(o);

等同于

var o=document.createElement("div");
o.style.cursor="pointer";
o.style.zIndex="100";
o.innerHTML="aaaa";
document.body.appendChild(o);

简化书写

8 元素下的元素

var x=document.getElementById("main");
var y=x.getElementsByTagName("p");

9 .getElementsByClassName //样式名
    getElementById
     getElementsByTagName // 标签名 如 ul li p div

10.如需改变 HTML 元素的样式,请使用这个语法:

document.getElementById(id).style.property=new style
例子:document.getElementById("p2").style.color="blue";

11. 显示和隐藏

<input type="button" value="隐藏文本" onclick="document.getElementById('p1').style.visibility='hidden'" />
<input type="button" value="显示文本" onclick="document.getElementById('p1').style.visibility='visible'" />

12. 添加节点有两种方法:
  <1> 用innerHtml注入
  <2> 用var para=document.createElement("p");然后 document.getElementById("div1").appendChild(para);


13. 移除元素
  var child=document.getElementById("p1");
  child.parentNode.removeChild(child);

14. JavaScript 提供多个内建对象,比如 String、Date、Array 等等。

15. 创建一个新对象:
  <1> person={firstname:"John",lastname:"Doe",age:50,eyecolor:"blue"};
  <2> person=new Object();person.firstname="Bill";person.lastname="Gates";

<3> 用初始函数创建
function person(firstname,lastname,age,eyecolor)
{
  this.firstname=firstname;
  this.lastname=lastname;
  this.age=age;
  this.eyecolor=eyecolor;
}

16. 成员函数:方法只不过是附加在对象上的函数。(function 内可以新建function)
  function person(firstname,lastname,age,eyecolor)
  {
    this.firstname=firstname;
    this.lastname=lastname;
    this.age=age;
    this.eyecolor=eyecolor;

    this.changeName=changeName;
    function changeName(name)
    {
      this.lastname=name;
    }
  }

17.字符串常用方法:
  indexOf() 来定位字符串中某一个指定的字符首次出现的位置。
  match() 来查找字符串中特定的字符,并且如果找到的话,则返回这个字符。
  replace() 方法在字符串中用某些字符替换另一些字符。
  length 返回字符串的长度


18. var date = new Date() 获得时间

19. 获得窗体大小
  var w=window.innerWidth|| document.documentElement.clientWidth|| document.body.clientWidth;
  var h=window.innerHeight||document.documentElement.clientHeight|| document.body.clientHeight;

20.提示窗:alert("文本")confirm("文本")prompt("文本","默认值")

21.可以用for (x in mycars) 遍历数组

22. 数组常用arr.join(".") 用.连接生成字符串,arr.concat(arr2)连接两个数组