1

我正在使用这个插件:http : //www.jquerynewsticker.com/ 我需要把 li 的内容包装起来<a href=""></a>

<ul id="js-news">
    <li class="news-item">This is text 1 ...</li>
    <li class="news-item">This is text 2 ...</li>
    <li class="news-item">This is text 3 ...</li>
    <li class="news-item">This is text 4 ...</li>
 </ul>

像这样:

<ul id="js-news">
        <li class="news-item"><a href="my-form">This is text 1 ...</a></li>
          <li class="news-item"><a href="my-form">This is text 2 ...</a></li>
          <li class="news-item"><a href="my-form">This is text 3 ...</a></li>
          <li class="news-item"><a href="my-form">This is text 4 ...</a></li>
</ul>

我认为字符串需要在这个字符串中。但我不知道如何:

script type="text/javascript">
    $(function () {
        $('#js-news').ticker({



        });
    });
</script>
4

2 回答 2

4

尝试这个:

$('li.news-item').each(function(){
  $(this).contents().wrap('<a href="#"/>');
});

演示:http: //jsbin.com/uqedeq/1/edit

于 2012-09-14T09:44:17.790 回答
1

我建议,只要您的用户不会/不能插入自己的链接元素:

$('li.news-items').contents().wrap('<a href="#" />');​

JS 小提琴演示

于 2012-09-14T09:45:22.643 回答