weixin_33713503 2015-03-30 07:30 采纳率: 0%
浏览 97

替换<li>中的文本

How can I replace - undefined with or remove it entirely? substr() is not a good idea because 'name' is always changing value. Please help.

<li>name - undefined</li>
<li>name - undefined</li>
<li>name - undefined</li>
<li>name - undefined</li>
<li>name - undefined</li>

here is my code...

 $.each(item.mguest,function(i,item)
 {
    $(".males-list li").first().after('<li class="mlist"><img src="icon/delete.png" title="REMOVE" class="delete-input" style="visibility:hidden;"/>' + item + '</li>')
});
  • 写回答

1条回答 默认 最新

  • 北城已荒凉 2015-03-30 07:34
    关注

    You can use .text( function ) with replace() in a handler function to update the text of the element.

    A function returning the text content to set. Receives the index position of the element in the set and the old text value as arguments.

    Here is an example:

    $(document).ready(function() {
      $('li').text(function(_, text) {
        return text.replace(' - undefined', ''); //In place of '' use text which you want.
      });
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <ul>
      <li>name - undefined</li>
      <li>name - undefined</li>
      <li>name - undefined</li>
      <li>name - undefined</li>
      <li>name - undefined</li>
    </ul>

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 软件定义网络mininet和onos控制器问题
  • ¥15 微信小程序 用oss下载 aliyun-oss-sdk-6.18.0.min client报错
  • ¥15 ArcGIS批量裁剪
  • ¥15 labview程序设计
  • ¥15 为什么在配置Linux系统的时候执行脚本总是出现E: Failed to fetch http:L/cn.archive.ubuntu.com
  • ¥15 Cloudreve保存用户组存储空间大小时报错
  • ¥15 伪标签为什么不能作为弱监督语义分割的结果?
  • ¥15 编一个判断一个区间范围内的数字的个位数的立方和是否等于其本身的程序在输入第1组数据后卡住了(语言-c语言)
  • ¥15 Mac版Fiddler Everywhere4.0.1提示强制更新
  • ¥15 android 集成sentry上报时报错。