jquery obtains the current value value by Name,id name

Source: Internet
Author: User

Name is the attribute value of the input tag, and jquery provides the attr () method to set/change the property value

$ ("Input:text"). attr ("name");
$ ("Input:text"). Prop ("name"); You can also get properties using the Prop () method



$ ("*[name= ' name ']"). After (' <div>hello world</div> '); Add an element outside the current

How jquery uses the Name property to take a value

Alert ($ ("Input[name= ' inputtest ')"). Val ());

Alert ($ ("input[type= ' text ']"). attr ("id")); This is the value of the ID, easy to remember to write here

$ ("Input[name= ' inputtest ')". each (

function () {

Alert (This). Val ());

}

)

Alert ($ ("Input[name= ' inputtest ')") [0].value];

Alert ($ ("Input[name= ' inputtest ')") [1].value];

Alert ($ ("Input[name= ' inputtest ')"). Get (0). value); You can also get a value here, equal to the two lines above

Alert ($ ("Input[name= ' inputtest ')"). Get (1). value);

  1. Value by name:
  2. $ ("input[name=' mobile ']"). Val ()
  3. Value by ID:
  4. $ ("#mobile_reg_form"). HTML ()
  5. The traversal is evaluated by name:
  6. $ ("input[name=' mobile ']"). each (
  7. function () {
  8. Alert (This). Val ());
  9. }
  10. )
  11. Remove input from the form:
  12. <script type="Text/javascript" language="javascript" charset="UTF-8">
  13. $ (document). Ready (function () {
  14. var a=$ ("form input");
  15. $.each (
  16. A
  17. function (Name,object) {
  18. Alert (name+ ":" +$ (Object). val ());
  19. }
  20. );
  21. });
  22. </Script>
  23. To get a value (multiple cases):
  24. $ ("input[name=' mobile ']") [0].value
  25. $ ("input[name=' mobile ']"). Get (1). Value
  26. Add a Delete style-----jquery--------
  27. To add a style to a label:
  28. $ ("#id"). AddClass ("style");
  29. Delete a label's style:
  30. $ ("#id"). Removeclass ("style");
  31. Note: the "#id" ID is the corresponding label of the Id,style is the name of the corresponding CSS style

jquery obtains the current value value by Name,id name

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.