[英]How to select id previously created in JQuery/Javascript?
I have table created dynamically after AJAX return call. 我在AJAX返回调用后动态创建了表。 Once table is built I need to update one of the elements.
建立表格后,我需要更新元素之一。 If I use JQuery selector to get the value for specified ID I see
undefined
in my Developer tools. 如果我使用JQuery选择器获取指定ID的值,则在开发人员工具中会看到
undefined
。 Here is example of my table: 这是我的桌子的例子:
var tbl = "<table class='tblData' id='tblMater'><caption id='numRec'>Records: "+numRecs+"</caption><thead><tr><th>Code</th><th>Sort Order</th><th>Name</th><th>Comment</th><th>Active</th><th>Edit</th><th>Delete</th></tr></thead><tbody>";
for(var i=0; i < numRecs; i++){
var jsRec = obj.DATA[i];
//Here I build td elements
}
tbl += "</tbody></table></div>";
Here is example of function where I test JQuery selector: 这是我测试JQuery选择器的函数示例:
function Test(){
console.log($('#numRec').val()); //I have tried getElementById() as well.
}
As I mentioned above I see undefined in my Console. 如上所述,我在控制台中看到未定义的内容。 If anyone knows the way how I can get the value from my table element please let me know.
如果有人知道如何从表格元素中获取价值,请告诉我。 Thank you.
谢谢。
val()
returns the value="" of an element. val()
返回元素的value =“”。 If you want the text of the node you want to use html()
or text()
instead. 如果您想要节点的文本,则可以改用
html()
或text()
。
Further more, if you want just the number, i'd suggest putting a span around it that you can specifically target before doing so. 此外,如果您只需要数字,我建议您在其周围放一个跨度,然后再专门确定目标范围。
尝试这个 :
$("#numRec").text();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.