{ var x=document.forms.myForm x[0].checked=false } </script> </head>
<body>
<form name="myForm"> <input type="checkbox" value="on"> <input type="button" onclick="check()" value="Check Checkbox"> <input type="button" onclick="uncheck()" value="Uncheck Checkbox"> </form>
</body> </html>
表单中的副选框的选择与取消
<html>
<head> <script type="text/javascript"> function check() { coffee=document.forms[0].coffee answer=document.forms[0].answer txt="" for (i=0;i<coffee.length;++ i) { if (coffee[i].checked) { txt=txt + coffee[i].value + " " } } answer.value="You ordered a coffee with " + txt } </script> </head>
<body> <form> How would you like your coffee?<br /><br /> <input type="checkbox" name="coffee" value="cream">With cream<br /> <input type="checkbox" name="coffee" value="sugar">With sugar<br /> <br /> <input type="button" name="test" onclick="check()" value="Send order"> <br /><br /> <input type="text" name="answer" size="50"> </form> </body>
</html>
副选框实现的功能(转换为大写)
<html> <body>
<script type="text/javascript"> function convertField(field) { if (document.form1.convertUpper.checked) { field.value=field.value.toUpperCase() } }
function convertAllFields() { document.form1.fname.value=document.form1.fname.value.toUpperCase() 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>
上一篇:网页制作中表单相关特效整理
下一篇:javascript的键盘控制事件
|