-1

我正在尝试找到一种解决方法,以从 SharePoint 2007 网站上的“公告摘要视图”中删除“by”行。由于各种原因,我在网上找到的任何东西似乎都不起作用 - 所以我想采取另一条路线,前提是一些有才华的灵魂会有所帮助。有谁知道如何让 jQuery 发挥一些魔力,以便第一个 HTML 块最终呈现为第二个 HTML 块?

区块 1:

<a onfocus="OnLink(this)" href="/Lists/Our%20Announcements/DispForm.aspx?ID=36" ONCLICK="GoToLink(this);return false;" target="_self">Title of Annoucement  </a><IMG SRC="/_layouts/1033/images/new.gif" alt="New">&nbsp;</span><br>by <nobr><span><A ONCLICK="GoToLink(this);return false;" HREF="/_layouts/userdisp.aspx?ID=2258">Lastname, FirstName I.</A><img border="0" height="1" width="3" src="/_layouts/images/blank.gif" alt="" /><a href="javascript:" onclick="IMNImageOnClick();return false;" class="ms-imnlink"><img title="" alt="No presence information" name="imnmark" border="0" valign="middle" height="12" width="12" src="/_layouts/images/blank.gif" sip="email@address.com" id="imn0,type=smtp" ></a></span></nobr></td><td width=20% align="right" nowrap class="ms-vb">&nbsp;4/15/2013 12:51 PM</td></tr><tr><td colspan=2 class="ms-vb"> <div id="{291345DC-BEAE-47B6-8F53-41C07838090C}36"><div class=ExternalClass5BF6EE28A88D436CAC2FE553E7F2CED7><div>

区块 2:

<a onfocus="OnLink(this)" href="/Lists/Our%20Announcements/DispForm.aspx?ID=36" ONCLICK="GoToLink(this);return false;" target="_self">Title of Annoucement  </a><IMG SRC="/_layouts/1033/images/new.gif" alt="New">&nbsp;</span></td><td width=20% align="right" nowrap class="ms-vb">&nbsp;4/15/2013 12:51 PM</td></tr><tr><td colspan=2 class="ms-vb"> <div id="{291345DC-BEAE-47B6-8F53-41C07838090C}36"><div class=ExternalClass5BF6EE28A88D436CAC2FE553E7F2CED7><div>

这是我需要删除的内容:

<br>by <nobr><span><A ONCLICK="GoToLink(this);return false;" HREF="/_layouts/userdisp.aspx?ID=2258">Lastname, FirstName I.</A><img border="0" height="1" width="3" src="/_layouts/images/blank.gif" alt="" /><a href="javascript:" onclick="IMNImageOnClick();return false;" class="ms-imnlink"><img title="" alt="No presence information" name="imnmark" border="0" valign="middle" height="12" width="12" src="/_layouts/images/blank.gif" sip="email@address.com" id="imn0,type=smtp" ></a></span></nobr>

----------------------------------------更新以获得更好的格式------ ------------- 真的没有什么我可以看到 jQuery 可以选择的。此外,这来自 SharePoint,因此我无法将任何 id 或 div 添加到生成的代码中。

区块 1:

    <TR>
      <TD width=80% class="ms-vb" style="padding-bottom: 3px">
        <span class="ms-announcementtitle"><a onfocus="OnLink(this)" href="/Lists/Our%20Announcements/DispForm.aspx?ID=36" ONCLICK="GoToLink(this);return false;" target="_self">Title of Annoucement  </a><IMG SRC="/_layouts/1033/images/new.gif" alt="New">&nbsp;</span>
        <br>by 
        <nobr>
            <span><A ONCLICK="GoToLink(this);return false;" HREF="/_layouts/userdisp.aspx?ID=2258">Lastname, FirstName I.</A><img border="0" height="1" width="3" src="/_layouts/images/blank.gif" alt="" /><a href="javascript:" onclick="IMNImageOnClick();return false;" class="ms-imnlink"><img title="" alt="No presence information" name="imnmark" border="0" valign="middle" height="12" width="12" src="/_layouts/images/blank.gif" sip="email@address.com" id="imn0,type=smtp" ></a></span>
        </nobr>
      </td>
      <td width=20% align="right" nowrap class="ms-vb">&nbsp;4/15/2013 12:51 PM</td>
    </tr>
    <tr>
        <td colspan=2 class="ms-vb"> 
            <div id="{291345DC-BEAE-47B6-8F53-41C07838090C}36">
            <div class=ExternalClass5BF6EE28A88D436CAC2FE553E7F2CED7>
            <div>
            <div>
                <p style="line-height:normal;margin:0in 0in 0pt;vertical-align:top" class=MsoNormal>
                    <b>
                        <span style="font-family:'Arial','sans-serif';color:black;font-size:9pt">
                            <em>A message from Firstname Lastname</em>
                        </span>
                    </b>
                </p>
                <p style="line-height:normal;margin:0in 0in 0pt;vertical-align:top" class=MsoNormal>
                    <span style="font-family:'Arial','sans-serif';color:black;font-size:9pt"></span> 
                </p>
                <p style="line-height:normal;margin:0in 0in 0pt;vertical-align:top" class=MsoNormal>
                    <span style="font-family:'Arial','sans-serif';color:black;font-size:9pt">Here is the message </span>
                </p>
                <p style="line-height:normal;margin:0in 0in 0pt;vertical-align:top" class=MsoNormal>
                    <span style="font-family:'Arial','sans-serif';color:black;font-size:9pt"></span> 
                </p>
                <p style="line-height:normal;margin:0in 0in 0pt;vertical-align:top" class=MsoNormal>
                    <span style="font-family:'Arial','sans-serif';color:black;font-size:9pt">To...
            </div>
        </TD>
    </TR>
    <TR>
        <TD>
            <font size=1>&nbsp;</font>
        </TD>
    </TR>

区块 2:

     <TR>
      <TD width=80% class="ms-vb" style="padding-bottom: 3px">
        <span class="ms-announcementtitle"><a onfocus="OnLink(this)" href="/Lists/Our%20Announcements/DispForm.aspx?ID=36" ONCLICK="GoToLink(this);return false;" target="_self">Title of Annoucement  </a><IMG SRC="/_layouts/1033/images/new.gif" alt="New">&nbsp;</span>
      </td>
      <td width=20% align="right" nowrap class="ms-vb">&nbsp;4/15/2013 12:51 PM</td>
    </tr>
    <tr>
        <td colspan=2 class="ms-vb"> 
            <div id="{291345DC-BEAE-47B6-8F53-41C07838090C}36">
            <div class=ExternalClass5BF6EE28A88D436CAC2FE553E7F2CED7>
            <div>
            <div>
                <p style="line-height:normal;margin:0in 0in 0pt;vertical-align:top" class=MsoNormal>
                    <b>
                        <span style="font-family:'Arial','sans-serif';color:black;font-size:9pt">
                            <em>A message from Firstname Lastname</em>
                        </span>
                    </b>
                </p>
                <p style="line-height:normal;margin:0in 0in 0pt;vertical-align:top" class=MsoNormal>
                    <span style="font-family:'Arial','sans-serif';color:black;font-size:9pt"></span> 
                </p>
                <p style="line-height:normal;margin:0in 0in 0pt;vertical-align:top" class=MsoNormal>
                    <span style="font-family:'Arial','sans-serif';color:black;font-size:9pt">Here is the message </span>
                </p>
                <p style="line-height:normal;margin:0in 0in 0pt;vertical-align:top" class=MsoNormal>
                    <span style="font-family:'Arial','sans-serif';color:black;font-size:9pt"></span> 
                </p>
                <p style="line-height:normal;margin:0in 0in 0pt;vertical-align:top" class=MsoNormal>
                    <span style="font-family:'Arial','sans-serif';color:black;font-size:9pt">To...
            </div>
        </TD>
    </TR>
    <TR>
        <TD>
            <font size=1>&nbsp;</font>
        </TD>
    </TR>
4

2 回答 2

0

用这个 :

$('.ms-partline').parent().parent().parent().remove();  

它只会删除共享点中的视图

于 2014-04-24T21:20:19.207 回答
0

你可以这样做来移除它,尽管它可能有助于了解包裹它的东西,这样你就不会意外移除需要保留的东西。在我的示例中,我刚刚在罪魁祸首周围放置了一个 div:

演示:http: //jsfiddle.net/lucuma/yyEXU/1/

代码:

$('div').html($('div').html().replace('by',''))

或者您可以使用 body 或 document 更通用:

$('body').html($('body').html().replace('by',''));

由于td's包含 by 您可以优化它并查找单词by,并且仅在需要时才对它们进行替换:

$('td').each(function() {
  if ($(this).text().indexOf('by')>-1) 
    $(this).html($(this).html().replace('by',''));
    $('nobr', this).remove();  // if the nobr contains by we remove this.
     // $(this).empty()  // this will remove the contents and keep the tags.
}
于 2013-04-15T19:32:45.077 回答