我可以迭代ap标签并更改为ul吗?

AJH*_*AJH 2 html javascript jquery

我正在尝试创建一个脚本,该脚本遍历带有几个文本句子的段落,并在每个句子的开头和结尾插入一个li标签.这可能吗?

所以,转过这一段

<p>
   Give your work the edge with this pencil. Awesome design, and chunky gold finish. Get the look. 
</p>
Run Code Online (Sandbox Code Playgroud)

进入这个无序列表

<p>
  <ul>
    <li>
      Give your work the edge with this pencil.
    </li> 
    <li>
      Awesome design, and chunky gold finish. 
    </li>
    <li>
      Get the look. 
    </li>
  </ul>
</p>
Run Code Online (Sandbox Code Playgroud)

Kyl*_*cey 5

$('p').each(function() {
  var $par = $(this),
      theText = $par.text().split('. ');
  $par.text('');
  $.each(theText, function(i, item) {
    if ($.trim(item).length > 0)
      $par.append('<li>' + item + '</li>');
  });
});
Run Code Online (Sandbox Code Playgroud)

未经测试,但你明白了.拆分,然后运行数组,包装在您的标签中.