簡體   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