菜鸟学习javascript实例教程(7)
2008-02-23 07:41:41来源:互联网 阅读 ()
<html>
<body>
<img border="0" src="hackanm.gif" width="48" height="48">
<br />
<img border="0" src="compman.gif" width="107" height="98">
<p>
<script type="text/javascript">
document.write("This document contains: " document.images.length " images.")
</script>
</p>
</body>
</html>
显示表单的名字
<html>
<body>
<form name="Form1">
Name: <input type="text" size="20">
</form>
<form name="Form2">
Age: <input type="text" size="3">
</form>
<p><b>You can use the form's number:</b></p>
<script type="text/javascript">
document.write("<p>The first form's name is: ")
document.write(document.forms[0].name "</p>")
document.write("<p>The second form's name is: ")
document.write(document.forms[1].name "</p>")
</script>
<p><b>Or, the form's name (will not work in Netscape):</b></p>
<script type="text/javascript">
document.write("<p>The first form's name is: ")
document.write(document.forms("Form1").name "</p>")
document.write("<p>The second form's name is: ")
document.write(document.forms("Form2").name "</p>")
</script>
</body>
</html>
事件对象
单击弹出窗口
<html>
<head>
<script type="text/javascript">
function whichButton()
{
if (event.button==1)
{
alert("You clicked the left mouse button!")
}
else
{
alert("You clicked the right mouse button!")
}
}
</script>
</head>
<body onmousedown="whichButton()">
<p>Click in the document. An alert box will alert which mouse button you clicked.</p>
</body>
</html>
单击弹出窗口显示鼠标的位置
<html>
<head>
<script type="text/javascript">
function show_coords()
{
x=event.clientX
y=event.clientY
alert("X coords: " x ", Y coords: " y)
}
</script>
</head>
<body onmousedown="show_coords()">
<p>Click in the document. An alert box will alert the x and y coordinates of the cursor.</p>
</body>
</html>
按一个键则显示该键的ASCII码
<html>
<head>
<script type="text/javascript">
function whichButton()
{
alert(event.keyCode)
}
</script>
</head>
<body onkeyup="whichButton()">
<p><b>Note:</b> Make sure the right frame has focus when trying this example!</p>
<p>Press a key on your keyboard. An alert box will alert the unicode of the key pressed.</p>
</body>
</html>
单击任何地方显示鼠标在页面的坐标
<html>
<head>
<script type="text/javascript">
function coordinates()
{
x=event.screenX
y=event.screenY
alert("X=" x " Y=" y)
}
</script>
</head>
<body onmousedown="coordinates()">
<p>
Click somewhere in the document. An alert box will alert the x and y coordinates of the cursor, relative to the screen.
</p>
</body>
</html>
单击之后显示文档的鼠标坐标
<html>
<head>
<script type="text/javascript">
function coordinates()
{
x=event.x
y=event.y
alert("X=" x " Y=" y)
}
</script>
</head>
<body onmousedown="coordinates()">
<p>
Click somewhere in the document. An alert box will alert the x and y coordinates of the cursor.
</p>
</body>
</html>
显示SHIFT是否被按下
<html>
<head>
<script type="text/javascript">
function isKeyPressed()
{
if (event.shiftKey==1)
{
alert("The shift key was pressed!")
}
else
{
alert("The shift key was NOT pressed!")
}
}
</script>
</head>
<body onmousedown="isKeyPressed()">
<p>
Click somewhere in the document. An alert box will tell you if you pressed the shift key or not.
</p>
</body>
</html>
单击显示我们页中的标签
<html>
<head>
<script type="text/javascript">
function whichElement()
{
var tname
tname=event.srcElement.tagName
alert("You clicked on a " tname " element.")
}
</script>
</head>
<body onmousedown="whichElement()">
<p>Click somewhere in the document. An alert box will alert the tag name of the element you clicked on.</p>
<h3>This is a header</h3>
<p>This is a paragraph</p>
<img border="0" src="ball16.gif" width="29" height="28" alt="Ball">
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:网页制作中表单相关特效整理
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
