Home > Web Front-end > JS Tutorial > body text

Example code for val() form value assignment in Jquery_jquery

WBOY
Release: 2016-05-16 17:25:39
Original
1229 people have browsed it

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
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!