如何使用jQuery删除标记内容的前6个字符?

Cor*_*ial 2 html jquery

我正在渲染RSS提要,每个内容部分的开头都有内容 - 它总是6个字符,我想使用jQuery删除它.

Feed的特定位的内容位于列表标记中,因此 <li>blahah Hello this is where I want to display from...</li>

摆脱" blahah "是目标.

更新:

提供的jQuery工作得很好,但我无法弄清楚为什么它将所有列表元素拉出来就好像它们是内联的一样!

你能解释为什么这个例子中的li标签 - jsfiddle.net/GhazG/5在渲染时碰到对方,而不是像这样出现 - jsfiddle.net/GhazG/6

use*_*716 7

这将删除页面上每个 <li>元素的前6个字符.我想你会希望你的选择器专门针对这个<li>问题.

   // Select your <li> element
var $li = $('li');

   // Get the text(), and call .substr() passing the number 6 as the argument
   //   indicating that you want to get the part of the string starting on
   //   index number 6 (the seventh character)
$li.text( $li.text().substr(6) );
Run Code Online (Sandbox Code Playgroud)

尝试一下: http ://jsfiddle.net/GhazG/

由于<li>页面上有多个需要更新的元素,因此您应该使用each循环:

试一试: http ://jsfiddle.net/GhazG/7/

$('li').each(function() {
    var $th = $(this);
    $th.text( $th.text().substr(6) );
});
Run Code Online (Sandbox Code Playgroud)

如果通过javascript将项目附加到DOM,您还可以选择执行追加之前删除字符.这可能是一种更好的方法.