admin管理员组文章数量:1302328
I'm tryng to get all the ID,value of each input element on 'page-templete1' and i didn't succeed
function Temp1() {
var input = [];
$('page-templete1 input[name][id][value]').each(function(){
input.push(this);
cc=$(this).attr('id'));
alert(cc); // trying to get one at time (not working)});
alert(input[0].id); // not working
alert(input[0].attr('id')); // not working
});
alert(input[0].id); // not working
alert(input[0].attr('id')); // not working
}
how can I get ID,value of all Input elements in a page and have access one them later note: I done know the IDs of the input elements or how many. there is an old post talking about similar problem but didn't solve my problem
I'm tryng to get all the ID,value of each input element on 'page-templete1' and i didn't succeed
function Temp1() {
var input = [];
$('page-templete1 input[name][id][value]').each(function(){
input.push(this);
cc=$(this).attr('id'));
alert(cc); // trying to get one at time (not working)});
alert(input[0].id); // not working
alert(input[0].attr('id')); // not working
});
alert(input[0].id); // not working
alert(input[0].attr('id')); // not working
}
how can I get ID,value of all Input elements in a page and have access one them later note: I done know the IDs of the input elements or how many. there is an old post talking about similar problem but didn't solve my problem
Share Improve this question edited Nov 16, 2017 at 7:45 Diaa Saada asked Feb 21, 2013 at 12:14 Diaa SaadaDiaa Saada 1,0561 gold badge12 silver badges22 bronze badges 1-
try removing the
[name][id][value]
at from the selector – Hugo Alves Commented Feb 21, 2013 at 12:17
6 Answers
Reset to default 5Depending on whether your "page" is an id you may need the dot or hash before the selector:
var results = [];
$('#page-templete1 input').each(function(){
results.push({
id: this.id,
value: this.value
});
});
Try the below code :
$(function(){
$("input").each(function(){
alert($(this).attr('id'))
})
})
var inputs = [];
$('page-templete1 input').each(function(){
var id=$(this).attr('id'),
val = $(this).val();
alert("id: " + id + " with value: "+ val);
inputs.push({id:id, value:val});
});
You are assigning an array to a variable: var inputs = [];
and then try to read the array by referencing an undefined variable: input.push(this);
(using input
instead of inputs
).
Try to use jquery input selector and iterate over it.
Try something like this
$(function(){
jQuery( "#pageTemplate :input" ).each(function(){
var id = this.id; // for id
var value = this.value; // for value
})
})
Note : you have to specify whether your page-templete1 is id or class
serializeArray will help you try this:
var array = jQuery('your input selector').serializeArray();
the result will be
array{{name="", value=""})
to access try this
var array = jQuery('input').serializeArray();
array.each(function(obj){
//do what with your object
});
本文标签: javascriptJQuery get IDValue of all Input elementsStack Overflow
版权声明:本文标题:javascript - JQuery: get ID,Value of all Input elements - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741710557a2393817.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论