JavaScript gets elements of the same ID

Source: Internet
Author: User

In the servlet, you can directly use

1 string[] Property=request.getparametervalues ("property"); // Properties

To get the property value of the same ID. But in JS, it won't work. We only get the elements in the way of finding nodes. With this approach, it is already transparent to us whether the ID is the same.

1property[0]=$ ("#property"). Val ();2relation[0]=$ ("#relation"). Val ();3propertyvalue[0]=$ ("#wordvalue"). Val ();4node=$ ("#property"). Parent (). Parent (). Next ();5     while(node.length>0){6Property[i]=node.children (": First"). Children (": First")). Val ();7Relation[i]=node.children (": First"). Next (). Children (": First"). Val ();8Propertyvalue[i]=node.children (": First"). Next (). Next (). Children (": First"). Val ();9Node=Node.next ();Teni++; One}

In the above example, set three array variables:

1 var property=New  Array (); 2 var relation=New  Array (); 3 var propertyvalue=New Array ();

where parent () returns the node's parents (only one node is returned).

Children () returns all the child nodes of the current node, if you use Property=node.children (). val (); error. If you are using children (": First"), you will be returned with the second child node.

Next () returns the next sibling node of the current node.

Node.length>0 is used to determine whether the current node exists.

This allows you to traverse all the desired nodes.

1 $.post ("Test/contextservlet", {property:property,relation:relation,2             Propertyvalue:propertyvalue},function (data) {autonode.html (data);});

The above uses JQ to pass values to the servlet.

JavaScript gets elements of the same ID

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.