javascript - 如何使用 jquery 在 .each() 中设置特定 id 的特定元素
问题描述
我有这么多DIV
,<p>
我想设置 .each() 尤其DIV's <p>
是我在下面的代码中完成的。
var Selected_type = 'business'; //which comes dynamically
var para_id = Selected_type + '_ltr';
var text = "";
$(para_id + "p").each(function(index) {
if (index < count) {
text += '<p>' + ($(this).text()).trim() + "</p><br>";
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div class="col-xs-12" id="business_ltr" style="max-height: none; display: none;">
<p>Learn how to transform your life for the better with 16 of the Web’s favorite entrepreneurship and leadership articles from this year.</p>
<p>Mental fortitude is essential for entrepreneurship, and in this wildly popular Forbes article, </p>
</div>
<div class="col-xs-12" id="study_ltr" style="max-height: none; display: none;">
<p>With all the emphasis placed on education in our society it is remarkable to realize that there has never been an actual technology of study or a technology of education. </p>
<p>The first little gate that has to be opened to embark upon study is the willingness to know. .</p>
</div>
但这显示我未定义并且没有显示任何结果。
但如果我设置$("p" ).each()
它正在工作,但它得到了一切<p>
,但我想要特别DIV's
<p>
谁能帮我解决这个问题
解决方案
推荐阅读
- bash - 使用 cat 从文件中将降价存储在变量中,以便在 gitlab-ci.yml 的 api 调用中扩展
- doctrine-orm - 通过 @Embedded 实体的属性使用 Doctrine Criteria 过滤集合
- mysql - 将数据从 kafka 复制到 mysql ,无法使用 DOcker 和 Debezium 连接到 JDBCSinkConnector
- java - 是否有任何选项可以使 getter 表达式更短?
- html - 为表格中单元格之间的空间着色
- python - Python 装饰类文档
- revit-api - 如果我使用 2 种不同类别的墙体结构材料,如何使用 revit api 为两个不同的层设置复合结构
- c# - 将 json 反序列化为列表时的空指针
- android - 如何在协调器布局中添加拉动刷新
- node.js - facebook graph api:将别人的页面订阅到我的应用程序