javascript this 用法
原文地址:http://www.cnblogs.com/daniel-shen/archive/2006/07/12/449280.html
javascript 中this 的用法:
1.<div onclick="// 可以在里面使用this">division element</div> this 指向div
2. <div id="elmtDiv">division element</div>
<script language="javascript">
var div = document.getElementById('elmtDiv');
div.attachEvent('onclick', EventHandler); //attachEvent把div的onclick事件和一个方法绑定
function EventHandler()
{
// 在此使用this
}
</script>在此this 指向window对象,若要引用div对象this.event.srcElement;
3、用DHTML方式在事件处理函数中使用this关键字:
<div id="elmtDiv">division element</div>
<script language="javascript">
var div = document.getElementById('elmtDiv');
div.onclick = function()
{
// 在此使用this
};
</script>产生的方法同上,但此处的this 指向div
4、类定义中使用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();//这是JavaScript模拟类定义中对this的使用,这个和其它的OO语言中的情况非常的相识。但是这里要求成员属性和方法必须使用this关键字来引用,运行上面的程序会被告知myName未定义。
5、为脚本引擎内部对象添加原形方法中的this关键字:
Function.prototype.GetName = function()
{
var fnName = this.toString();
相关文档:
WPF的WebBrowser和WinForm的WebBrowser有一定区别。
要向其中注入javascript脚本,经过本人试验,下面一条路可以走通:
mshtml.HTMLDocument htmlDoc = Browser.Document as mshtml.HTMLDocument;
var head = htmlDoc.getElementsByTagName("head").Cast<HTMLHeadElement>().First();
var script = (IHTMLS ......
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>图片跑马灯</title>
</head>
<body>
<div align="center" id="demo" style="overflow: hidden; height: 33px; width: 400px;
&nb ......
1.获取URL
获取url的方法,直接用location就可以了,window.location或window.loation.href也可以。
2.分析URL
运用location获取的url的属性为object,要对其进行字符串的分析操作,需要先将其转换为字符串。
用location来进行处理,首先将其转换为字符串,用函数toString(),URL.toString();
附一些URL参数
完整的U ......
网速很慢,但又得打开 Flash 是一件很痛苦的事情,特别是 Silverlight 来临之际,这个技术可能有点用
具体代码如下
<SCRIPT LANGUAGE="JavaScript">
var starttime = new Date()
</SCRIPT>
<img src="images/ConvLogo.JPG?id=<%Int(37462 * Rnd +&n ......