Home > Article > Web Front-end > How to get the input value appended by jquery
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;
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;
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() { // ……});
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!