Use JavaScript to locate the navigation menu after page refreshing [original]

Source: Internet
Author: User

Posted on blog.csdn.net/zxub in the early morning.

In actual design, we often need to use the jump menu. After the jump, the page will be refreshed. At this time, we need to make the jump menu display the one we just selected. After trying many methods, I feel like using "menuobj. selectedindex = "is the most direct implementation. Here, variables need to be transferred between pages. I tried it and never passed it over. I don't know what went wrong, so I'm so depressed.
Suddenly, I thought of the address of a dynamic web page, such as AAA = BBB & CCC = DDD. What would happen if I added such an HTML page? I tried it. It is the same as the original one. Okay. You can put the parameters in the address bar and use a document. the location address is down, and the parameter we want is intercepted in the obtained address bar string. This "menuobj. selectedindex = "can be used.
Just like this, the above thought is thrown into the page. The Code is as follows:
<Script language = "JavaScript" type = "text/JavaScript">
Function setselectedindex (OBJ) // OBJ indicates the jump menu
{
VaR selectedindex;
VaR url = Document. location;
VaR serachtaglocation = NULL;
VaR urlstring = "\" "+ URL +" \ ""; // if no value is added, the object does not support this method.
Serachtaglocation = urlstring. indexof ("typeid \ = ");
If (serachtaglocation! =-1)
{
VaR selecttypeid = urlstring. substr (serachtaglocation + 7, 1) // The above is the T location.
VaR optstring = "\" "+ obj. Options [1]. Value +" \ ""; // The following four rows are for my needs.
VaR optserachtaglocation = optstring. indexof ("= ");
VaR opttypeid = optstring. substr (optserachtaglocation + 1, 1)
Selectedindex = selecttypeid-(OptTypeid-1 );
}
Else selectedindex = 0;
OBJ. selectedindex = selectedindex; // you can locate it now.
}
</SCRIPT>
You only need to run the above function after the navigation menu to locate the function. Of course, after the jump, the address must be added with a serial code such as AAA = BBB, it depends on your needs.
Alas ~ Don't speak up, it's finally quite comfortable, hey.

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.