日期:2014-05-16  浏览次数:20569 次

JavaScript笔记(五)
今天先贴两张图上了,明天接着来
不好意思,发到了论坛里面,但是由于写了4篇文章,博客每天只能存3篇,所以也没办法,
贻笑大方了,误入的大侠请转身。


窗口对象的属性和方法:


    格式:
    [window.]属性
    [window.]方法(参数)

    opener.属性
    opener.方法(参数)
    self.属性
    self.方法(参数)
    parent.属性
    parent.方法(参数)
    top.属性
    top.方法(参数)

    窗口名称.属性
    窗口名称.方法(参数)






窗口对象的事件处理程序:


    onBlur onDragDrop onError onFocus onLoad onMove onResize onUnload
<Script>

function checkPassword(testObject) {
if (testObject.value.length < 6) {
    alert("密码长度不得小于6");
    testObject.focus();
    testObject.select();
}
}

</Script>
请输入密码:
<INPUT TYPE="text" onBlur="checkPassword(this)">


<Script>

if (confirm("你满十八岁了吗?"))
    location = "adult.htm";
else
    alert("等你成年以後再来吧!");

</Script>


这个可能被拦截
<Script>

var bgColor =
prompt("你喜欢哪一种底色:\n浅蓝色请按1,粉红色请按2",1)

if (bgColor == 1) document.bgColor = "#CCFFFF";
else if (bgColor == 2) document.bgColor = "#FFCCFF";
else document.bgColor = "#FFFFFF";

</Script>


屏幕对象:

描述屏幕的显示及颜色属性。
屏幕对象的属性:

格式: screen.属性



<Script>

with (document) {
    write ("您的屏幕显示设定值如下:<P>");
    write ("屏幕的实际高度为", screen.availHeight, "<BR>");
    write ("屏幕的实际宽度为", screen.availWidth, "<BR>");
    write ("屏幕的色盘深度为", screen.colorDepth, "<BR>");
    write ("屏幕区域的高度为", screen.height, "<BR>");
    write ("屏幕区域的宽度为", screen.width);
}

</Script>

<Script>

if ( screen.width < 800 || screen.colorDepth < 8 ){
    var msg = "本网站最佳浏览模式为 800 * 600 * 256";
    alert(msg);
}

</Script>


事件对象:

当事件发生时,浏览器自动建立该对象,并包含该事件的类型、鼠标坐标等。

事件对象的属性:
格式:event.属性


<Script>

function getEvent(evnt) {
eventWin = open ('','','width=200,height=100');
with (eventWin.document) {
     write("事件类型:", event.type);
     write("<br>鼠标的x坐标:", event.screenX);
     write("<br>鼠标的y坐标:", event.screenY);
}
}

document.write ("单击...")
document.onmousedown = getEvent;
</Script> 


<Script>

function getCoordinate(evnt) {

if (document.all) {
   x = event.screenX;
   y = event.screenY;
}
else {
   x = evnt.screenX;
   y = evnt.screenY;
}
status = "水平坐标:"+ x + ";垂直坐标:"+ y;
}

document.onmousemove = getCoordinate;

</Script>


<Script>

function whichKey(evnt) {

if (document.all) {
    x = event.button;
    if( x==1 ) alert("你单击了左键");
    if( x==2 ) alert("你单击了右键");
}

else {
    x = evnt.button;
    if( x==1 ) alert("你单击了左键");
    if( x==3 ) alert("你单击了右键");
    return false;
}
}

document.onmousedown = whichKey;
document.write("请单击鼠标左/右键");

</Script>


历史对象:

用以存储客户端最近访问的网址清单。
格式:
history.属性
history.方法(参数)
历史对象的属性: