function showFormElements(theForm) { str="Form Elements: " for (i=0; i<theForm.length; i++) str+=" \n " + theForm.elements[i].name alert(str) } </script> </head>
<body> <form> First name: <input type="text" name="fname" size="20"> <br /> Last name: <input type="text" name="lname" size="20"> <br /><br /> <input type="button" name="button1" value="Display name of form elements" onClick="showFormElements(this.form)"> </form> </body>
</html>
副选框的选择和取消
<html>
<head> <script type="text/javascript"> function check() { var x=document.forms.myForm x[0].checked=true }
function uncheck() { 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()
上一篇:网页制作中表单相关特效整理
下一篇:javascript的键盘控制事件
|