我想添加两个函数,javascript
以便在第一个验证后,第二个必须验证并返回值。但就我而言,只有一个正在执行:
这是代码:
<html>
<script type="text/javascript">
function validate(){
var name_value=document.getElementById('qs').value;
if(name_value=="")
{
alert("Please enter your keyword");
}
}
var ray={ajax:function(st)
{
this.show('load');
},
show:function(el)
{
this.getID(el).style.display='';
},
getID:function(el)
{
return document.getElementById(el);
}
}
</script>
<style type="text/css">
#load {
background: none repeat scroll 0 0 #F7F7F7;
border: 1px double #999999;
font-family: "Trebuchet MS",verdana,arial,tahoma;
height: 50px;
left: 45%;
line-height: 50px;
margin-left: -150px;
margin-top: -50px;
position: absolute;
text-align: center;
top: 50%;
width: 350px;
z-index: 1;
}
</style>
<body>
<div id="load" style="display:none;"><strong>Please wait while we process your request...</strong></div>
<form action="http://www.example.com" method="post" onSubmit="validate() && return ray.ajax()">
<input type="text" value="" name="q" id="qs">
<input type="submit" value="Search">
</form>
</body>
</html>
在上面的代码中,只有当我在标签validate()
中删除时才会起作用。但我希望两者都能工作,即 if , show , else show消息。return ray.ajax()
<form>
textbox
isEmpty
alert
Please wait...
如何实现?提前致谢...