2013-04-15 52 views
-1

我試圖找到解決方法,從SharePoint 2007網站上的公告摘要視圖中刪除「by」行。出於各種原因,我在網上找到的東西似乎都行不通 - 所以我想採取另一條路線,提供一些有才華的人才會有所幫助。有誰知道如何使jQuery的工作有些神奇,所以HTML的第一塊可以最終呈現爲第二塊HTML?jQuery可以刪除這段文字嗎?

塊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 protected]" 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 protected]" id="imn0,type=smtp" ></a></span></nobr> 

---------- ------------------更新以獲得更好的格式化---------------------------- --- 真的沒有什麼,我可以看到哪些jQuery的CA ñ選擇。此外,這是來自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 protected]" 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> 
+0

,這樣很容易看你應該格式化代碼! –

+0

是否有任何帶有類或標識符的周邊元素可以讓您識別正確的元素? – jfriend00

+0

我已經更新了我的答案。如果在這種情況下單詞'by'總是在'td'內,那麼你可以用這個單詞搜索'td's',並且只替換那些或者你可以在整個身體上進行替換。取決於你的情況。 – lucuma

回答

0

爲此,您可以刪除它,雖然它可能有助於知道什麼是包裝,所以你不要意外刪除的東西那需要保持。在我的例子,我只是放在一個div周圍的罪魁禍首:

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

代碼:

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

或者你可以使用體或文檔更加普遍:

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

由於td's包含by你可以優化這個並尋找單詞by並且只做那些替換如果你wa NT:

$('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. 
} 
+0

您的解決方案是否也會刪除人員姓名?我需要在''標籤之間的所有內容都被刪除。 – Mark

+0

對不起,我誤解了..你是否也要刪除nobr標籤?我添加了代碼來刪除標籤和/或刪除它們的內容。 – lucuma

+0

是的,整個行標着「這是我需要刪除的東西:」(並不意味着任何意思)。順便說一句,謝謝你的幫助。 – Mark

0

使用此:

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

它只會刪除那些意見是在SharePoint