javascript - 分割字符串并创建分页

标签 javascript jquery html

<div><p class="pagi">page 1 content</p><p class="pagi">page 2 content</p><p class="pagi">page 3 content</p></div>

我有上面的字符串,我必须构建分页,标志是 pagi 类。如果上面的 html 是实际的 html,但它是字符串,我知道该怎么做,我不能使用 jquery .find('pagi')

需要帮助,我被困住了。

最佳答案

Wrap the string using jQuery然后使用 find()方法。

var $ele = $(str).find('.pagi');

var str = '<div><p class="pagi">page 1 content</p><p class="pagi">page 2 content</p><p class="pagi">page 3 content</p></div>';

var $ele = $(str).find('.pagi');

console.log($ele.length);
$ele.each(function() {
  console.log($(this).text());
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

关于javascript - 分割字符串并创建分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41582363/

相关文章:

javascript - 通过在 Google map HTML 中点击获取特定点的纬度和经度

javascript - 云函数: Avoid Nesting Promises for different conditions

javascript - 如何通过在html5中单击按钮将网页转换为pdf

javascript - 字符串 IndexOf 在一个数组的句子中

javascript - 将 String 值转换为 int 以在 highchart 中使用

css - 仅使用 css 或 ngClass 更改点击时的图标

javascript - 限制 TypeScript 中的类型组合

javascript - 使用 contenteditable div 获取和设置光标位置

html - 如何对齐标签和文本区域?

php - 将 PHP 网站转换为基于 HTML 的网站