[英]Using Javascript in HTML returning false even if the condition is true
如果搜索欄中的輸入不是“ Dog”,我正在HTML中使用Javascript返回彈出錯誤。 但是,當輸入為“ Dog”時,它仍然顯示彈出錯誤。
<div class="search" >
<input type="text" name="s"
<a href="/redirect.php">
<button id="find" type="submit"
onclick="javascript: if(document.getElementById('find').value!='Dog')
{
alert('This animal does not exist in the system, try another one...');
return false;
}"> </button>
</div>
如果搜索欄中的輸入為“ dog”,則該代碼應轉到redirect.php。 代碼哪里出問題了?
嘗試這個
<div class="search" >
<input type="text" id="find" name="s" />
<a href="/redirect.php">
<button type="submit"
onclick="javascript: if(document.getElementById('find').value!='Dog') {
alert('This animal does not exist in the system, try another one...');
return false;
}"> </button>
</div>
之所以不能使用,是因為button元素具有查找 ID而不是文本字段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.