Home > Web Front-end > JS Tutorial > jquery gets input value problem explanation_jquery

jquery gets input value problem explanation_jquery

WBOY
Release: 2016-05-16 18:21:13
Original
1050 people have browsed it

Later, with the help of the great Baidu, I finally found the cause of the problem:

Copy the code The code is as follows:

$("") is a jquery object, not a dom element
value is an attribute of dom element
jquery corresponds to val
val(): Get the first matching element current value.
val(val): Set the value of each matching element.

So, the code should be written like this:
Copy the code The code is as follows:

Value: val = $("#id")[0].value;
Assignment:
$("#id")[0].value = "new value";
Or $("#id").val("new value");

Or this also works: val = $("#id").attr("value");
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