我有一个用 classic asp 创建的旧页面,包含一个表单,在检查表单中的可用值后,我尝试使用 JavaScript 函数提交表单。
HTML:
<form method="POST" action="vendorCheckDates.asp" name="Searchform" id="submit_Form">
Select Type of Search: </b>
<select size="1" name="Query" class="button">
<option selected name="vNAME" value="vNAME"> Name</option>
<option name="vNUM" value="vNUM"> Number</option>
<option name="vEM" value="vEM">Email </option>
<option name="vFAX" value="vFAX">Fax </option>
</select>
<b>:</b>
<input type="text" name="hsearch" id="hsearch">
<fieldset class="fieldset">
<legend><strong>Type</strong></legend>
<input type="radio" value="gov" name="tType" >Gov
<input type="radio" value="gfos" name="tType">GFOS
</fieldset>
<input type="button" value="Search" name="hfind" Onclick="SubmitForm()">
</form>
功能
function SubmitForm() {
var hsearch = document.all.submit_Form.hsearch.value;
var tType = document.getElementById('tType').value;
if ((hsearch = ! '') && (hsearch = ! null)) {
if ((tType = ! '') && (tType = ! null)) {
document.all.submit_Form.submit();
} else { alert("please select search type");}
} else { alert("please write search criteria"); }
}
当我运行表单时,字段 hsearch 为空,但是当我单击提交时,该值将为 true,这很奇怪,因为我仍然没有在输入字段 hsearch 中写入任何内容,这就是为什么 JavaScript 函数中的 sels 部分不起作用
最佳答案
我认为您使用了错误的运算符。应该是
if ((hsearch != '') && (hsearch != null)) {
if ((tType != '') && (tType != null)) {
关于javascript - JavaScript 中的警报功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24402754/