javascript-basic-window-object
通用类demo
by boxcore
HTML
<h1 id="obj1">111</h1>
<h1 id="obj2">222</h1>
<h1 id="obj3">333</h1>
<button id="btobj1">click: this 1</button>
<button id="btobj2" onclick="show(this)">click: this 2</button>
JavaScript
//找到对象
obj1=document.getElementById("obj1");
//加样式
obj1.style.color="red";
//加事件
obj1.onclick=function(){
alert(this.outerHTML);
}
// 对象的赋值
var obj=new Object();
obj.name="user1";
console.log(obj.name);
var num="10abc";
alert(parseInt(num)); // 10
alert(Number(num)); // NaN
// this 使用
// this 1
var btobj=document.getElementById("btobj1");
btobj.onclick=function(){
alert(this.outerHTML);
}
// this 2
function show(obj){
alert(obj.outerHTML);
}