<form action="search.php" name="sform" method="get" class="sform">
<div class="setextout"><input type="text" name="setext" value="" class="setext"/></div>
<div class="sebtnout"><input type="button" name="Sevalue" value="谷歌" class="sbtn" onclick="onfirst();"/><input type="button" name="Sevalue" value="百度" class="sbtn" onclick="onfirst();"/></div>
</form>
<!--header -->
<script>
function onfirst(){
var tex=document.sform.setext.value;
var decide=document.sform.Sevalue.value;
var link;
if (decide=="百度"){
link="http://www.baidu.com/s?wd="+tex;
}
else if(decide=="谷歌"){
link="http://www.google.com.hk/search?q="+tex;
}
window.open(link);
}
</script>
怎么我这个取到的link都是underfine的?
------解决方案--------------------
document.sform.Sevalue取到的是数组,没有value这个property
------解决方案--------------------
- HTML code
<form action="search.php" name="sform" method="get" class="sform"> <div class="setextout"> <input type="text" name="setext" value="" class="setext"/> </div> <div class="sebtnout"> <input type="button" name="Sevalue" value="谷歌" class="sbtn" onclick="onfirst(this);"/> <input type="button" name="Sevalue" value="百度" class="sbtn" onclick="onfirst(this);"/> </div> </form> <!--header --> <script> function onfirst(obj) { var tex = document.sform.setext.value; //var decide=document.sform.Sevalue.value; //name值为Sevalue的按钮有两个,这样取值显然是错误的 var decide = obj.value; alert(decide); var link; if (decide == "百度") { link = "http://www.baidu.com/s?wd=" + tex; } else if (decide == "谷歌") { link = "http://www.google.com.hk/search?q=" + tex; } window.open(link); } </script>