1: <script language=”JavaScript”>... 2: function checkField(field) ...{ 3: if (field.value == “”) ...{ 4: window.alert(“You must enter a value in the field”); 5: field.focus(); 6: } 7: } 8: </script> 9: <form name=”myForm” action=”target.html”> 10: Text Field: <input type=”text” name=”myField”onBlur=”checkField(this)”> 11: <br/><input type=”submit”> 12: </form>
50 验证Select项
1: function checkList(selection) ...{ 2: if (selection.length ==0) ...{ 3: window.alert(“You must make a selection from the list.”); 4: returnfalse; 5: } 6: returntrue; 7: }