简体   繁体   English

如何从列表项的文本中删除日期

[英]How to remove dates from list items' text

Our registration site provides a review page before people submit their registration.我们的注册网站在人们提交注册之前提供了一个审查页面。 The review panel includes everything they have checked so the list is individual and variable.审查小组包括他们检查过的所有内容,因此该列表是单独且可变的。 Each item begins with a date/time that is distracting and needs to be hidden/removed.每个项目都以一个令人分心的日期/时间开始,需要隐藏/删除。

I have been successful in removing it for the last item listed but can't get it to look the same for each list item when more than one is selected. I have been successful in removing it for the last item listed but can't get it to look the same for each list item when more than one is selected.

Here is the HTML of a list where three options have been chosen:这是一个列表的 HTML,其中选择了三个选项:

<ul style="list-style: none;">
  <li>and the sub events
    <ul>
      <li>6/30/2020 9:00 AM - 10:00 AM : Volunteer at North Campus</li>
      <li>6/30/2020 1:00 PM - 2:00 PM : Volunteer at South Campus</li>
      <li>6/30/2020 4:00 PM - 5:00 PM : Volunteer at West Campus</li>
    </ul>
  </li>
</ul>

The script that removes the date and time for the LAST line is:删除最后一行的日期和时间的脚本是:

$("div[class$=registrationDetails]").find('li').last().each(function() {
    $(this).text( $(this).text().split(':').pop() );
});

How do I make it the same for all lines?如何使所有行都相同?

Assuming that the entire list is within the div[class$=registrationDetails] div, the nested <li> elements will cause a problem if you just find <li> (the outer <li> found will strip a bunch of the child elements' text).假设整个列表都在div[class$=registrationDetails] div 内,那么嵌套的<li>元素如果只找到<li>就会出现问题(找到的外层<li>会剥离一堆子元素'文本)。 Once you do that, you won't have to grab ".last()" anymore.一旦你这样做了,你就不必再抢“.last()”了。 You need to specify that you only want the inner <li> elements.您需要指定您只需要内部<li>元素。 So:所以:

Get rid of the .last() and replace the .find('li') with .find('li > ul > li') .去掉.last()并将.find('li')替换为.find('li > ul > li')

var listItems = $(".registrationDetails li"); listItems.each(function() { $(this).text( $(this).text().split(':').pop() ); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM