日期:2014-05-16  浏览次数:20385 次

如果搜索内容是默认值的话就跳转到指定页面
<input type="text" name="ss" value="Sou"><input type="submit" name="bt" value="SouSuo">
点击提交时,如果输入框里是默认值的话就跳到指定的页面,否则正常提交,怎么写

------解决方案--------------------
if(value=="Sou"){window.location=''}else{submit();}

------解决方案--------------------
<form action="test.asp" onsubmit="return check(this)">
<input type="text" name="ss" value="Sou">
<input type="submit" name="bt" value="SouSuo">
</form>
<script type="text/javascript">
function check(f){
if( f.ss.value == f.ss.defaultValue ){
location.href = 'http://baidu.com/'
return false;
}
}
</script>
------解决方案--------------------
HTML code
<!DOCTYPE HTML>
<html>
 <head>
  <title> New Document </title>
  <meta charset="uft-8">
 </head>
<script>
 function ceshi(e){
 e = e || window.event;
 // 阻止submit的默认行为
e.returnValue = false;
if(e.preventDefault){
    e.preventDefault();
}

var el=document.getElementById('Sou');
if(el.value == "Sou")
{
window.location = 'http://www.baidu.com'
}else{
document.getElementById('frm').submit();
}
}
</script>
 <body>
<form id="frm" action="http://g.cn">
  <input style="text" id="Sou" name="ss" value="Sou"><input type="submit" value="SouSuo" onclick="ceshi()">
</form>
 </body>
</html>