JavaScript implements a way to jump a page through a select tag _javascript tips

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.