判斷兩個(gè)文本框中只輸一個(gè)的實(shí)例:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>標(biāo)題頁(yè)</title>
<SCRIPT LANGUAGE="JavaScript">
function checkFields()
{
name = document.submitform.name.value; //獲取姓名
email = document.submitform.email.value; //獲取郵箱
if ((name == "") && (email == "") ) { //如果兩者都為空
alert("請(qǐng)輸入姓名和郵箱!");
return false;
}
else
return true;
}
</script>
</head>
<body>
<form name=submitform onSubmit="return checkFields()">
名字和郵箱只需要輸入一個(gè)即可<br>
<br>
<table border=0>
<tr>
<td align=center>名字</td><td> </td>
<td align=center>Email</td></tr><tr>
<td align=center><input type=text name=name value="" onFocus="document.submitform.email.value='';" size=10></td>
<td align=center>或</td>
<td align=center><input type=text name=email value="" onFocus="document.submitform.name.value='';" size=10></td>
</tr>
<tr>
<td colspan=3 align=center><input type=submit value="提交"></td>
</tr>
</table>
</form>
</body>
</html>