使用本身动态创建的foreach jQuery动态检索文本框值 [英] dynamically retrieve textbox values using foreach jquery which itself is dynamically created
本文介绍了使用本身动态创建的foreach jQuery动态检索文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从输入文本框中动态检索值:
How to dynamically retrieve values from input text box :
$(":input").each(function(){alert($(this).text());});
案例:
动态列名称取自xml源&以这种方式绑定:
Dynamically column names are taken from xml source & binded in this manner :
<script type="text/javascript" language="javascript">
$(document).ready(function(){
$.ajax({
type: "GET",
url: "GetColumnNames.xml",
dataType: "xml",
success: function(xml) {
var cWidth = 100/(xml.getElementsByTagName("Column")).length;
$(xml).find('Column').each(function(){
var cId = $(this).find('Id').text();
var cName = $(this).find('Name').text();
$('<td id='+cId+' width='+cWidth+'>'+cName+'</td>').appendTo('#page-wrap');
$('<label for='+cName+'>'+cName+'<input type="text" name='+cName+'id='+cName+' value="" class="text ui-widget-content ui-corner-all" /></label>').appendTo('#moreItems');
});
}
});
});
</script>
#moreItems
是另一个div的一部分,另一个div是模式弹出窗口的一部分,我想访问其中的值,
The #moreItems
is part of another div which is part of modal popup and i want to access values within that,
所以
验证后,我会这样:
if ( bValid ) {
$(":text").each(function(){
alert($(this).text());
});
}
但是我仍然无法访问输入值.
But still i am not able to access input values.
注意:
它与:
如何使用JQuery检索文本框值?, Jquery检索动态创建的元素的值, 如何使用以下方法检索文本框的标题和名称jQuery?,
正在寻找您的帮助..
Looking for your help ..
谢谢.
推荐答案
您缺少$
符号.应该是:
$(":text").each(function(){
alert($(this).val());
});
您还应该尝试生成格式正确的HTML,并用引号字符分隔属性:
You should also try to generate well-formed HTML, with attributes delimited by quote characters:
$('<td id="'+cId+'" width="'+cWidth+'">'+cName+'</td>').appendTo('#page-wrap');
$('<label for="'+cName+'">'+cName+'<input type="text" name="'+cName+'" id="'
+cName+'" value="" class="text ui-widget-content ui-corner-all" /></label>')
.appendTo('#moreItems');
这篇关于使用本身动态创建的foreach jQuery动态检索文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文