菜鸟学习javascript实例教程(6)

2008-02-23 07:41:41来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折


document.form1.lname.value=document.form1.lname.value.toUpperCase()
}
</script>

<form name="form1">
First name:
<input type="text" name="fname" onChange="convertField(this)" size="20" />
<br />
Last name:
<input type="text" name="lname" onChange="convertField(this)" size="20" />
<br />
Convert fields to upper case
<input type="checkBox" name="convertUpper" onClick="if (this.checked) {convertAllFields()}" value="ON">
</form>

</body>
</html>

文档对象

显示连接的数量

<html>
<body>

<a name="A">First anchor</a><br />
<a name="B">Second anchor</a><br />
<a name="C">Third anchor</a><br />
<br />

Number of anchors in this document:
<script type="text/javascript">
document.write(document.anchors.length)
</script>

</body>
</html>

显示当前所在服务器的地址

<html>
<body>

The domain name for this site is:
<script type="text/javascript">
document.write(document.domain)
</script>

</body>
</html>


显示当前页面的地址:

<html>
<body>

<p>The referrer of a document is the URL of the document that linked to a document.</p>

The referrer of this document is:
<script type="text/javascript">
document.write(document.referrer)
</script>

<p>In this case it is a frame page that is linking to this document. IE returns the URL of the frame page and Netscape returns the URL of the document linking to this document.</p>

</body>
</html>


显示当前文档的标题

<html>
<head>
<title>MY TITLE</title>
</head>

<body>
The title of the document is:
<script type="text/javascript">
document.write(document.title)
</script>
</body>

</html>

用按钮来显示当前页面的地址

<html>
<head>
<script type="text/javascript">
function showURL()
{
alert(document.URL)
}
</script>
</head>

<body>
<form>
<input type="button" onclick="showURL()" value="Show URL">
</form>
</body>

</html>


通过单击可以知道当前的标签

<html>

<head>
<script type="text/javascript">
function getElement()
{
var x=document.getElementById("myHeader")
alert("I am a " x.tagName " element")
}
</script>
</head>

<body>
<h1 id="myHeader" onclick="getElement()">Click to see what element I am!</h1>
</body>

</html>


显示表单中元素的个数

<html>

<head>
<script type="text/javascript">
function getElements()
{
var x=document.getElementsByName("myInput")
alert(x.length " elements!")
}
</script>
</head>
<body>

<form >
<input name="myInput" type="text" size="20"><br />
<input name="myInput" type="text" size="20"><br />
<input name="myInput" type="text" size="20"><br />
<br />
<input name="mybutton" type="button" onclick="getElements()" value="Show how many elements named 'myInput'">
</form>
</body>

</html>


打开一个新的文档,显示几个文字

<html>

<head>
<script type="text/javascript">
function docOpen()
{
document.open()
document.write("<h3>Hello World!</h3>")
}
</script>
</head>

<body>
<form>
<input type="button" onclick="docOpen()" value="Open a new document">
</form>
</body>

</html>


打开一个新的文档,并显示新的文档

<html>
<head>
<script>
function replace()
{
var newDoc=document.open("text/html","replace")
var txt="<html><body>FUN!!!!</body></html>"
newDoc.write(txt)
newDoc.close()
}
</script>
</head>

<body>
<h1>Learning how to access the DOM is....</h1><br />
<Input type ="button" value = "Finish Sentence" onclick="replace()">
</body>

</html>


计算表单的个数

<html>

<body>
<form name="Form1">
Name: <input type="text" size="20">
</form>
<form name="Form2">
Age: <input type="text" size="3">
</form>

<script type="text/javascript">
txt="This document contains: " document.forms.length " forms."
document.write(txt)
</script>
</body>

</html>


计算一个页面中图形的个数

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:网页制作中表单相关特效整理

下一篇:使用Javascript创建XML文件