`
DoubleEO
  • 浏览: 154535 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

javascript的一些总结(5)

阅读更多
12.JavaScript中的onLoad和onUnload
当前页面(包括所有图像)完成从服务器上的加载时,就会发生onLoad
由于onLoad事件发生在HTML文档加载和显示完毕之后,所以不能在onLoad事件处理程序中使用document.write或document.open,否则会覆盖当前文档。
下面是一个一放到超链接,就显示名字的小例子
HTML代码如下
<ul>
<li><a href="order.html" id="order">Order Form</a>
<li><a href="email.html" id="email">Email</a>
<li><a href="complain.html" id="complain">Complaint Department</a>
</ul>
<h2 id="description"></h2>
<script language="JavaScript" type="text/javascript" src="linkdesc.js">
</script>


linkdesc.js
function cleardesc() {
   d = document.getElementById("description");
     d.innerHTML = "";
}
function hover(e) {
    if (!e) var e = window.event;
    // which link was the mouse over?
    whichlink = (e.target) ? e.target.id : e.srcElement.id;
    // choose the appropriate description
    if (whichlink=="order") desc = "Order a product";
    else if (whichlink=="email") desc = "Send us a message";
    else if (whichlink=="complain") desc = "Insult us, our products, or our families";
    // display the description in the H2
    d = document.getElementById("description");
    d.innerHTML = desc;
}

orderlink = document.getElementById("order");
orderlink.onmouseover=hover;
orderlink.onmouseout=cleardesc;
emaillink = document.getElementById("email");
emaillink.onmouseover=hover;
emaillink.onmouseout=cleardesc;
complainlink = document.getElementById("complain");
complainlink.onmouseover=hover;
complainlink.onmouseout=cleardesc;

其中e.target代表元素所对应的对象,e.target.id代表对象的DOM对象的id.
如果同时定义了onKeyDown和onKeyPress事件处理函数,则先调用onKeyDown,如果返回true,则再调用onKeyPress


13.JavaScript中的window对象

Window对象的属性
closed 窗口是否关闭
defaultStatus 窗口状态栏的默认文本
document Document对象
history History对象
length Window对象的frame个数
location Location对象
name Window对象的名称
opener 打开当前Window的窗口的引用
parent 父窗口
self 返回当前窗口的引用
status 窗口状态栏文本
top 最顶层窗口

Window对象的方法
alert([Message]) 显示带有警告信息Message的窗口,并有“确定”按钮
blur() 移除本窗口的焦点
clearInterval(iIntervalID) 取消先前用setInterval方法开始的标识为iIntervalID的间隔事件
clearTimeout(iTimeoutID) 取消先前用setTimeout方法开始的标识为iTimeoutID的超时事件
close() 关闭当前窗口
confirm([message]) 显示带有确认信息message的窗口,有“确定”和“取消”按钮
createPopup() 创建弹出窗口,返回该窗口对象的引用
focus() 使本窗口获得焦点
moveBy(x,y) 将窗口的位置移动到指定的x和y偏移值
moveTo(x,y) 将窗口左上角的屏幕位置移动到指定的x和y位置
open() 打开新窗口,显示指定的页面
print() 打印与窗口关联的文档
prompt([message][,defaultValue]) 显示提示对话框,带有提示消息message和默认值defaultValue的输入框,返回用户输入的字符串
resizeBy(x,y) 更改窗口的当前位置缩放指定的x和y偏移量
resizeTo(x,y) 将窗口的大小更改为指定的宽度值x和高度值y
scrollBy(x,y) 将窗口滚动x和y偏移量
scrollTo(x,y) 将窗口滚动到指定的x和y偏移量
setInterval(code,ms[,language]) 每经过ms毫秒后执行代码code,language指定语言属性。返回整形标识,以便clearInterval方法取消该定时器
setTimeout(code,ms[,language]) 经过ms毫秒后执行代码code,language指定语言属性。返回整形标识,以便clearTimeout方法取消该定时器
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics