<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>