日期:2014-05-16 浏览次数:20305 次
<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>