今天分享关于对搜索表单是否为空进行判断,如果为空,即弹出提示搜索关键词为空,代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<!--搜索表单-->
<script type= "text/javascript" >
function notNull() {
if (document.keyinput.kw.value.toString().trim().length <= 0) {
alert( "您未输入关键词!" );
document.keyinput.kw.focus();
return false ;
} else {
return true ;
}
}
</script>
<div class = "search clearfloat" id= "search" >
<form method= "get" action= "http://www.zjkweiqi.cn/ search.php" class = "search-form" name= "keyinput" >
<input type= "text" name= "kw" placeholder= "请输入商品/产品名,就能获取您需要的产品下载信息!" />
<button type= "submit" onclick= "return notNull()" >搜一下</button>
</form>
</div>
<!--搜索表单-->
|