Search for element a using url _ javascript skills

Source: Internet
Author: User
This article mainly introduces the implementation of searching for element a through url to solve some practical problems. If you are interested, refer to the following example to illustrate a previous project: when adding students, no class data. You need to automatically jump to the class display page.

Problem: students, classes, and other data are stored in the jsp file of iframe. The student management button is in the menu bar of main.html.

Mian page menu

Class Management:

Student Management:

The jsp in iframe is constantly changing.

Solution:

In Student Management jsp, find the class management tag of the parent form by id, and click

The Code is as follows:


Vertex (window.parent.doc ument). find ("# folder_12"). click ();


Later, the menu bar is changed to dynamic, and the menu id is also dynamic.

What you want is to get it through the url and click.

The Code is as follows:


Class Management


The value to be obtained is the changeContent ('url parameter') of The onClick method ')

View the Code directly:

The Code is as follows:


// Lele.info (subject (window.parent.doc ument). find (""));
Vertex (window.parent.doc ument). find ("# OutFolder a"). each (function (index, domEle ){
// Var s = $ (domEle). attr ("onclick") + "";
// Var start = s. indexOf ('classmanager/classList. do ');
Var str = domEle. attributes. onclick. value; // use js to obtain the onclick attribute value and search for the url
Var start = str. indexOf ('classmanager/classList. do ');
If (start> 0 ){
$ (DomEle). click ();
}
});


Summary: I used jquery to find the method and get the onclick attribute. I used indexOf to report an error and added a space to convert it to string.

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.