gpt4 book ai didi

jquery - 如何从每个循环内的类的子级获取标签文本? (jQuery)

转载 作者:行者123 更新时间:2023-12-02 01:09:11 24 4
gpt4 key购买 nike

所以我目前一直在尝试获取几个输入字段的标签文本

enter image description here

http://codepen.io/leongaban/pen/fJGie

^ 在上面的代码笔中,我创建了 2 个电话输入字段。但是一直无法获得每个标签的文本。最初我在输入上有 added_phone 类,但后来将它移到了父级 li

我试过 $(this.children) 没有错误,但没有输出,试过 var tag = $(this).children.label.text() 但是得到了一个错误

enter image description here

var elems = $('.added_phone');

elems.each( function(i) {
console.log(i);

var tag = $(this.children.label).text();
var value = $(this).val();

console.log('tag = '+tag);
console.log('value = '+value);
});


你看到我在这里做错了吗?

最佳答案

$(this).children.label.text()

是 jQuery 的无效语法,你可能是这个意思:

$(this).children("label").text()

关于jquery - 如何从每个循环内的类的子级获取标签文本? (jQuery),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19190503/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com