jquery 取多个相同id 的input的值_html/css_WEB-ITnose

WBOY
Release: 2016-06-21 09:47:02
Original
1408 people have browsed it

html jquery

有三个input
<input id="d" value="1"><input id="d" value="3"><input id="d" value="14">
Copy after login


如何通过jquery取得所有的input的值?并相加用循环么?
如何取得1+3+14的值?

回复讨论(解决方案)

把id换成class  找获得class的方法  不要重复id

每个页面的ID只能是唯一的。
$(function(){
var sum = 0;
$(".d").each(function(){
sum += parseInt($(this).val());
})
alert(sum);
})

每个页面的ID只能是唯一的。
$(function(){
var sum = 0;
$(".d").each(function(){
sum += parseInt($(this).val());
})
alert(sum);
})


谢了,已OK

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!