Javascript 使用名称attirbute逐个获取文本值

Javascript 使用名称attirbute逐个获取文本值,javascript,jquery,Javascript,Jquery,我有3个html元素 <h3 contenteditable class="education" name="education[index][University]>1</h3> <span contenteditable class="education" name="education[index][time]>2</span> <p contenteditable class="education" name="education[i

我有3个html元素

<h3 contenteditable class="education" name="education[index][University]>1</h3>
<span contenteditable class="education" name="education[index][time]>2</span>
<p contenteditable class="education" name="education[index][description]>3</p>
在高级中感谢您尝试以下方法:

$(函数(){
var输出=$('[name^=“教育[索引]”).map(函数(){
返回$(this.html();
}).get().join('\n');
警报(输出);
});

1.
2.

3

将元素包装在容器中,然后迭代这些元素的子元素。否则,您将不得不编写3个丑陋的(在本例中,考虑到所需的字符转义量)和脆弱的选择器。如果愿意,您甚至可以使用
map()
。如果我使用这个var-education=$(“.education”).text(),那么输出将只是生成所需HTML的一种情况。@rorymcrossan;我将获得所有文本值。好的。但是我需要在获得每个文本值后有一行新行。我如何才能获得它。因为我想用json类型保存在db中。education
包含这些内容的元素?现在如何输出值?我只是更新了html类
1
2
3