码迷,mamicode.com
首页 > 其他好文 > 详细

2015/12/15--Document对象

时间:2015-12-16 00:08:02      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:

<html>

<head>

<script type = "text/javascript">

//使用document.write()输出流写文本

document.write("hello,world!");

//使用document.write()输出流写HTML

document.write("<h1>welcome to my world!</h1>");

</script>

</head>

<body onmousedown = "show_coords(event)">

<p>referrer 属性返回加载本文档的文档的 URL。</p>

<p>该文档的标题是:

      该文档的URL:

      该文本的referer:

<script type = "type /javascript">

//返回当前文档的标题

document.write("document.title");

//返回当前文本的URL

document.write("document.URL");

//返回当前文本的referer

document.write("document.referer");

//返回下载当前文档的服务器域名

document.write("document.domain");

//使用getElementById()方法

function getValue(){

var x  = document.getElementById("myHeader");

alert(x.innerHTML);

}

//使用getElementByName()方法

function getElements(){

var X = document.getElementByName("myInput");

alert(X.length);

}

//打开一个新的文档,输入一些内容,然后关闭它。

function creatNewDoc(){

var newDoc = document.open("text.html","replace");

var txt = "<body><html>welcome my dear!</html></body>";

newDoc.write("txt");

newDoc.close();

}

//返回文档中瞄的数目

document.write("document.anchor.length");

//返回文档中第一个秒的innerHTML

document.write(document.anchor[0].innerHTML);

//计算文档中表单的数目

document.write("文档包含" + document.forms.length + "个表单");

//访问集合中项目

document.write("<p>第一个表单名称是" + document.form[0].name + "</p>");

document.write("<p>" + document.getElementById("form1").name + "</p>");

//计算文档中图像数目

document.write("文档中包含" + document.img.length + "张照片");

//哪个鼠标按钮被点击

function whichButton(event){

var btnNum = event.button;

if(btnNum == 2){

alert ("You check the right button!");

}else if(btnNum == 0){

alert("You check the left button!");

}else if(btnNum == 1){

alert("You check the middle button!");

}else{

alert("您点击了 +  + 号键",我不能够确定它的名称。);

}

}

//光标的坐标是?

function show_coords(event){

X1 = event.clientx;

Y1 = event.clienty;

alert("x坐标是“ + X1,"y的坐标是” +Y1);

}

//被按按键的unicode?

function whichButton1(event){

alert(event.keyCode);

}

//相对于屏幕,光标的坐标是?

function coordinates(event){

a = event.screenx;

b = event.screeny;

alert("X=" + a,"Y=" + b);

}

//shift键被按了吗?

function isKeyPressed(event){

if(shiftKey == 1){

alert("The shiftKey was checked!");

}else{

"The shift key was Not pressed!"

}

}

</script>

</p>

//shift键被按了吗?

<p>在文档中点击某个位置,消息框会告诉你是否按下了shift键。</p>

//相对于屏幕,光标的坐标是?

<p>点击文档中的某个位置,消息框会显示鼠标对于屏幕的坐标。</p>

//光标的坐标是?

<p><b>注释:</b>在测试这个例子时,要确保右侧的框架获得了焦点。</p>
<p>在键盘上按一个键。消息框会提示出该按键的 unicode。</p>

<p>请在文档中点击,一个消息框会显示文本的x和y坐标。</p>

//哪个鼠标按钮被点击

<p>请在文档中点击鼠标按钮,一个消息框会提示您点击了哪个鼠标按键。</p>

//计算文档中图像数目

<img border = "0"  src = "01.jpg">

<br>

<img border = "0" src = "02.jpg">

//访问集合中项目

<form id = "form1" name = "form1">your name <input type = "text" size = "20"></form>

<form id = "form2" name = "form2">Your cars<input type = "text"  size = "20"></form>

<p>要访问集合中的项目,你既可以访问项目名称,也可以使用项目编号。</p>

//计算文档中表单的数目

<form name = "form1"></form>

<form name = "form2"></form>

<form name = "form3"></form>

//返回文档中瞄的数目

<a name = "one">第一个苗</a>

<a name = "two">第二个苗</a>

<a name = "three">第三个苗</a>

//打开一个新的文档,输入一些内容,然后关闭它。

<input type = "button" onclick = "creatNewDoc()" value = "打开然后写入一个新的文档。">

//使用getElementByName()方法

<input type = "text" id = "myInput" size = "30"><br>

<input type = "text" id = "myInput" size = "30"><br>

<input type = "text" id = "myInput" size = "30"><br>

<br>

<input type = "button" onclick = "getElements()" value = "名为"myInput"的元素有几个">

<h1 id = "myHeader" onclick = "getValue()">headline</h1>

<p>点击标题,会显示它的值。</p>

</body>

<//html>

2015/12/15--Document对象

标签:

原文地址:http://www.cnblogs.com/whatcanido/p/5049779.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!