<LI> 使用 jQuery 自动换行文本



我需要用<span>将文本包装在无序列表中

尝试这个,但它似乎不起作用...

$('li').each(function(){
    var text = $(this).text();
    text = text.replace(/^(w){1}/, "<span>$1</span>");
    $(this).html(text);
});

你可以使用 jQuery 的 .wrap() 方法

$('li').each(function(){
    $(this).contents().wrap('<span></span>');       
});

http://jsfiddle.net/7HdER/

您可以使用

wrapInner方法:

$('li').wrapInner('<span/>')​​​​​​;

http://jsfiddle.net/UrTw5/

$('li').each(function(){
    var text = $(this).text();
    text = "<span>" + text + "</span>";
    $(this).html(text);
});

最新更新