作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一些具有相同类的标签,我想获取它们的每个值并将其附加到一个 div 如何做到这一点
<p class="adr">location1</p>
<p class="adr">location2</p>
<p class="adr">location3</p>
<p class="adr">location4</p>
for (i=1;i<$(".adr").length;i++) {
$("#test").append($(".adr").html() + "</br>");
}
结果:
位置1
位置1
位置1
位置1
好像apppend了4次first class,如何得到1 and 2 and 3 and 4?
最佳答案
在 jquery 中使用 each
获取所有 adr
类的文本。不要逐行append
,因为它需要更多的执行时间。尝试作为一个整体追加,希望这有帮助
var str=''
$('.adr').each(function(e){
str+=$(this).text()+ "<br>"
})
$("#test").html(str)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p class="adr">location1</p>
<p class="adr">location2</p>
<p class="adr">location3</p>
<p class="adr">location4</p>
<div id =test></div>
关于javascript - 如何获取相同类名的每个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55877771/
现在我正在尝试实现 flash programming specification对于 PIC32MX。我正在使用 PIC32MX512L 和 PIC32MX512H。 PIC32MX512L最终必须
我是一名优秀的程序员,十分优秀!