繁体   English   中英

JavaScript中的警报功能不起作用

[英]alert function in JavaScript is not working

我有一个用clasic 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为空,但是当我单击Submit时,该值将为true,这很奇怪,因为我仍然没有在输入字段hsearch中编写任何内容,这就是JavaScript函数中sels部分无法工作的原因

我认为您使用的是错误的运算符。 它应该是

 if ((hsearch != '') && (hsearch != null)) {               
        if ((tType != '') && (tType != null)) {

代替:

var hsearch = document.all.submit_Form.hsearch.value; 

尝试:

var hsearch = document.getElementById('hsearch').value; 

您始终可以通过发出如下alert来调试该值:

alert(hsearch)

您必须编写hsearch != ''而不是hsearch = ! '' hsearch = ! ''

您正在执行的操作不是检查值,而是分配返回true的值。

hsearch = ! ''
=> hsearch = !''
=> hsearch = true
=> true

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM