jquery Gets the value of an array object

Source: Internet
Author: User

When we develop with jquery, we encounter a situation where name has multiple or similar name. At this point we need to get a value for one of them or to get their values separately, we can use jquery to get an array of objects before we get one of them. First put the code on:

Description

Mode one: var orderId = $ ("input[name= ' Jqueryarray ')") [0].value;

$ ("input[name=' Jqueryarray ')") [0] is an input object, so you can directly use the native JS object. value to get

Way two:$ ($ ("Input[name= ' Jqueryarray ')") [i]). Val ();

                 $ (" Input[name= ' Jqueryarray ') ") [i] is an input object , So you can't call the Val () method in jquery, if you want to use the Val () method in jquery, you need to $ (" Input[name= ' Jqueryarray ' ] ") [i] to the jquery object, which is $ ($ ("Input[name= ' Ajaxorderid ')") [i]);

Way Three: $ ("input[name^= ' Jqueryarray ')"). each (function (i) {if (i = = 2) alert (this.value);});

Use the Each () function of jquery to loop around and get the values. Note that this is the native DOM object.


jquery Gets the value of an array object

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.