<script type="text/javascript">
var number = 1;
var obj = {
number: 2,
showNumber: function(){
this.number = 3;
(function(){
console.log(this.number);
})();
console.log(this.number);
}
};
obj.showNumber();
</script>
<input id="test" type="button" value="按钮" onClick="test()"/>
function test(){alert(this)}
document.getElementById("test").addEventListener("click",test);
// 可以在里面使用this ">division element // 可以在里面使用this ">division element
division element
var div = document.getElementById('elmtDiv');
div.attachEvent('onclick', EventHandler);
function EventHandler()
{
// 在此使用this
}
// -->
division element
var div = document.getElementById('elmtDiv');
div.attachEvent('onclick', EventHandler);
function EventHandler()
{
// 在此使用this
}
// -->
division element
lt;mce:script language="javascript">
var div = document.getElementById('elmtDiv');
div.onclick = function()
{
// 在此使用this
};
/ -->
division element
var div = document.getElementById('elmtDiv');
div.onclick = function()
{
// 在此使用this
};
// -->
function JSClass()
{
var myName = 'jsclass';
this.m_Name = 'JSClass';
}
JSClass.prototype.ToString = function()
{
alert(myName + ', ' + this.m_Name);
};
var jc = new JSClass();
jc.ToString();
function JSClass()
{
var myName = 'jsclass';
this.m_Name = 'JSClass';
}
JSClass.prototype.ToString = function()
{
alert(myName + ', ' + this.m_Name);
};
var jc = new JSClass();
jc.ToString();
function.prototype.GetName = function()
{
var fnName = this.toString();
fnName = fnName.substr(0, fnName.indexOf('('));
fnName = fnName.replace(/^function/, '');
return fnName.replace(/(^\s+)|(\s+$)/g, '');
}
function foo(){}
alert(foo.GetName());
function.prototype.GetName = function()
{
var fnName = this.toString();
fnName = fnName.substr(0, fnName.indexOf('('));
fnName = fnName.replace(/^function/, '');
return fnName.replace(/(^\s+)|(\s+$)/g, '');
}
function foo(){}
alert(foo.GetName());
view plaincopy to clipboardprint?
function JSClass()
{
this.m_Text = 'division element';
this.m_Element = document.createElement('DIV');
this.m_Element.innerHTML = this.m_Text;
this.m_Element.attachEvent('onclick', this.ToString);
}
JSClass.prototype.Render = function()
{
document.body.appendChild(this.m_Element);
}
JSClass.prototype.ToString = function()
{
alert(this.m_Text);
};
var jc = new JSClass();
jc.Render();
jc.ToString();
function JSClass()
{
this.m_Text = 'division element';
this.m_Element = document.createElement('DIV');
this.m_Element.innerHTML = this.m_Text;
this.m_Element.attachEvent('onclick', this.ToString);
}
JSClass.prototype.Render = function()
{
document.body.appendChild(this.m_Element);
}
JSClass.prototype.ToString = function()
{
alert(this.m_Text);
};
var jc = new JSClass();
jc.Render();
jc.ToString();
height: expression(this.parentElement.height);"> division element height: expression(this.parentElement.height);"> division element
view plaincopy to clipboardprint?
function OuterFoo()
{
this.Name = 'Outer Name';
function InnerFoo()
{
var Name = 'Inner Name';
alert(Name + ', ' + this.Name);
}
return InnerFoo;
}
OuterFoo()();
function OuterFoo()
{
this.Name = 'Outer Name';
function InnerFoo()
{
var Name = 'Inner Name';
alert(Name + ', ' + this.Name);
}
return InnerFoo;
}
OuterFoo()();
view plaincopy to clipboardprint? var variableName; //变量定义 //作用域:函数定义范围内 //使用方法:直接使用variableName this.varName; //成员变量定义 //作用域:函数对象定义范围内及其成员函数中 //使用方法:this.varName var variableName; //变量定义 //作用域:函数定义范围内 //使用方法:直接使用variableName this.varName; //成员变量定义 //作用域:函数对象定义范围内及其成员函数中 //使用方法:this.varName
view plaincopy to clipboardprint?
function JSClass()
{
var varText = "func variable!"; //函数中的普通变量
this.m_Text = 'func member!'; //函数类的成员变量
this.m_Element = document.createElement('DIV'); //成员变量,创建一个div对象
this.m_Element.innerHTML = varText; //使用函数的普通变量
this.m_Element.attachEvent('onclick', this.ToString); //给这个对象的事件连上处理函数
this.newElement = document.createElement('DIV');
this.newElement.innerHTML = "new element";
this.newElement.m_Text = "new element text!"; //给创建的对象建个成员
this.newElement.onclick = function()
{
alert(this.m_Text); //指向div对象的成员
};
}
JSClass.prototype.Render = function()
{
document.body.appendChild(this.m_Element); //把div对象挂在窗口上
document.body.appendChild(this.newElement);
}
JSClass.prototype.ToString = function()
{
alert(this.m_Text); //指向窗口(window)对象
};
function initialize(){
var jc = new JSClass();
jc.Render();
jc.ToString(); //里面的this指向JSClass类的实例,里面有m_Text成员
}
// -->
initialize();
// -->
function JSClass()
{
var varText = "func variable!"; //函数中的普通变量
this.m_Text = 'func member!'; //函数类的成员变量
this.m_Element = document.createElement('DIV'); //成员变量,创建一个div对象
this.m_Element.innerHTML = varText; //使用函数的普通变量
this.m_Element.attachEvent('onclick', this.ToString); //给这个对象的事件连上处理函数
this.newElement = document.createElement('DIV');
this.newElement.innerHTML = "new element";
this.newElement.m_Text = "new element text!"; //给创建的对象建个成员
this.newElement.onclick = function()
{
alert(this.m_Text); //指向div对象的成员
};
}
JSClass.prototype.Render = function()
{
document.body.appendChild(this.m_Element); //把div对象挂在窗口上
document.body.appendChild(this.newElement);
}
JSClass.prototype.ToString = function()
{
alert(this.m_Text); //指向窗口(window)对象
};
function initialize(){
var jc = new JSClass();
jc.Render();
jc.ToString(); //里面的this指向JSClass类的实例,里面有m_Text成员
}
// -->
initialize();
// -->
func variable! new element
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有