這可能是一個非常愚蠢的問題,但我無法弄清楚該網站的javascript命令,根據文本字段是否爲空來決定是否填充文本字段實際上填滿了我的代碼在這裏。對輸入文本的文本字段使用Javascript命令
<html>
<head>
<title>Contact Us</title>
<link rel="stylesheet" type="text/css" href="main.css">
<style type="text/css">
#main-container{
padding-left: 3px;
padding-right: 3px;
}
#left-bar{
text-align: right;
}
#left-bar, #right-bar{
border: 2px solid gray;
}
#top-nav-bar{
border-top: 1px solid gray;
border-bottom: 2px solid gray;
border-left: 2px solid gray;
border-right: 2px solid gray;
}
#navTextn{
float: right;
padding-right: 20px;
padding-top:10px;
}
#navTextc{
float: right;
padding-right: 20px;
padding-top:10px;
}
#navTexth{
float: right;
padding-right: 20px;
padding-top:10px;
}
#Contus{
float:right;
padding-right: 30px;
padding-top:10px;
}
#logo{
height: 20px;
width: 100px;
padding-top: 10px;
padding left: 10px;
}
</style>
<script type="text/javascript">
function validator(){
if(document.mUs.bfinderm.text)
alert("Thank you for your submission");
else
alert("No text has been entered");
}
</script>
<title>Tickit</title>
</head>
<body id="body">
<div id="topline">
</div>
<div id="top-nav-bar">
<a href="Homework.html"><image id="Logo" src="Tickit.png"></a>
<a id="Contus" href="ContactUs.html">Us</a>
<a id="navTextn">News</a>
<a id="navTextc" href="Calendar.html">Calendar</a>
<a id="navTexth" href="Homework.html">Home</a>
</div>
<table id="main-container">
<tr>
<td id="left-bar" valign="top">
<a id="plinks" >Profile</a><br>
<a id="plinks" >Mail</a><br>
<a id="plinks" href="Homework.html">Work Stream</a><br>
<a id="plinks" href="calendar.html">Calendar</a><br>
<a id="plinks" href="Events.html">Events</a><br>
</p>
</td>
<td id="main" valign="top">
If you find any bugs with the website, please leave a message to us in the box below <br> <br>
<form name="mUs">
Message Us:<br> <input type="text" name="bfinderm" />
<input type="button" value="Send" onClick="validator()" />
</form>
</td>
<td id="right-bar" valign="top">
</td>
</tr>
</table>
</body>
</html>
就像一個複選框,驗證()的代碼將被選中
<script type="text/javascript">
function validator(){
if(document.stackflowrun.stflr.checked)
alert("Yes it is checked!");
else
alert("Check that shit boul!");
}
</script>
那麼,什麼是等效驗證器()命令文本字段的選擇嗎?
function validator(){
if(document.mUs.bfinderm.text)
alert("Thank you for your submission");
else
alert("No text has been entered");
}
</script>
(文本不是它)
如果您只是使用'val()'你可以看到他們輸入的內容。 – jamespick