The example in this article describes the way JavaScript implements a Web page jump through a select tag. Share to everyone for your reference, specific as follows:
We often encounter the need to use the Select tag to jump to the new page, the DW generated code is too complex, then there is no streamlined code to achieve it? After careful study found the following pieces of code, very good.
Say not much, straight to the subject.
The core code of the face-to-face jump is: "Location.href=value"
The core code to open the new page is: "window.open ()"
The code is divided into four categories:
1, the current page directly jump:
<select name= "" onchange= "Javascript:location.href=this.value;" >
<option value= "http://www.jb51.net" selected= "selected" >jb51</option>
<option value= " Http://www.163.com ">163</option>
<option value=" http://www.sina.com ">sina</option>
<option value= "http://www.sohu.com" >sohu</option>
</select>
2, new page pop-up jump:
<select name= "" Onchange= "Javascript:window.open (this.options[this.selectedindex].value)" >
<option Value= "Http://www.jb51.net" selected= "selected" >jb51</option>
<option value= "http://www.163.com" >163</option>
<option value= "http://www.sina.com" >sina</option>
<option value= " Http://www.sohu.com ">sohu</option>
</select>
3, the current page click button Jump:
<form name= "Frm2" action= "" >
<select name= "Page2" > <option value= "http://www.jb51.net"
Selected= "selected" >jb51</option>
<option value= "http://www.163.com" >163</option>
<option value= "http://www.sina.com" >sina</option>
<option value= "http://www.sohu.com" >sohu </option>
</select>
<input type= "button" value= "Submit" onclick= "javascript:location.href= Document.frm2.page2.options[document.frm2.page2.selectedindex].value; " />
</form>
4, new Page click button Jump:
<form name= "frm" action= "" >
<select name= "page" >
<option value= "Http://www.jb51.net" Selected= "selected" >jb51</option>
<option value= "http://www.163.com" >163</option>
<option value= "http://www.sina.com" >sina</option>
<option value= "http://www.sohu.com" >sohu </option>
</select>
<input type= "button" value= "Submit" onclick= "Javascript:window.open ( Document.frm.page.options[document.frm.page.selectedindex].value) "/>
</form>
These are four common ways to jump.
There is also a more concise code for the current page jump:
<select name= "onchange=" Self.location.href=options[selectedindex].value ">
<option value=" http:// Www.baidu.com "> Baidu </option>
<option value=" http://www.163.com "> NetEase </option>
</ Select>
This is also very good.
More readers interested in JavaScript-related content can view the site topics: "JavaScript window operations and tips summary", "JavaScript traversal algorithm and tips summary", "JavaScript switching effects and techniques summary", " JavaScript Search Algorithm Tips Summary, "JavaScript animation effects and techniques Summary", "JavaScript Error and debugging skills Summary", "JavaScript data structure and algorithm skills summary" and "JavaScript Mathematical operation Summary"
I hope this article will help you with JavaScript programming.