Home  >  Article  >  Web Front-end  >  Example code for val() form value assignment in Jquery_jquery

Example code for val() form value assignment in Jquery_jquery

WBOY
WBOYOriginal
2016-05-16 17:25:391224browse

jQuery provides the powerful val() method to handle value-related operations.
Get the value of a single select and the value of a multi-select.

Copy code The code is as follows:

HTML code:

< /p>





jQuery code:
$("p").append(
" Single: " $("#single").val()
" Multiple: " $("#multiple").val() .join(", ")
);
Result:
[

Single:SingleMultiple:Multiple, Multiple3< ;/p>]


Get the value in the text box
HTML code:
Copy codeThe code is as follows:


jQuery code:
$("input").val() ;

Result:
some text
The following is how var() can get/assign the form element value
Copy code The code is as follows:




val() method



< body>




< input type="button" value="Input">








Note: var data=$("#myId").val();
If myid does not exist, data is undefined
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn