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

How to get the input value appended by jquery

小云云
Release: 2018-03-17 09:30:57
Original
4270 people have browsed it

If you use jquery to add an input box (name="price") to the pop-up window or the page through append, and want to get the value, this solution is quite surprising. During testing, it often happens If you don't expect this, it's easy to get around it. This article mainly shares with you how to get the input value added by append in jquery.

Note:

First make sure there are several input boxes with name="price" on your page, because some pop-up content is written on the page, and then append the page The input box in is appended to the pop-up window, resulting in two identical input boxes on the page; in the same way, when adding an element with a specified id, you must also check whether there is the same id in the page

Through jquery Methods to get values

$('input[name="price"]').val();
$('input[name="price"]').attr('value');
$('input[name="price"]')[0].value;
$('input[name="price"]').prop('value');
$('input[name="price"]').get(0).value;
Copy after login

Get values ​​through js methods

var inputVal = document.getElementsByName('price')[0].value;
var inputVal = document.getElementsByName('price').item(0).value;
var inputValue = document.getElementById('price').value;
Copy after login

Of course there are more than these methods, you can choose according to your preference. . . .

Bind click events to dynamically generated buttons

$('body').on('click', '.btn', function() {    // ……});
Copy after login

Related recommendations:

jquery append and appendTo usage analysis

Jquery append method usage problems

jQuery method analysis--append()

The above is the detailed content of How to get the input value appended by jquery. For more information, please follow other related articles on the PHP Chinese website!

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