2012-09-17 49 views
-3

我想在表格中包含已存在的文本(如下所示)的span标签。使用jQuery围绕已存在于表格中的文本围绕SPAN标签

文本中span标签包装:

Build Muscle and Train Harder<br> &nbsp; Boost Energy without the 
Calories<br> &nbsp; Promote Nitric Oxide Production 

我的HTML:

<table width="100%" cellspacing="0" cellpadding="0" border="0"> 
    <tbody> 
     <tr> 
      <td>Build Muscle and Train Harder<br> &nbsp;Boost Energy without the Calories<br> &nbsp; Promote Nitric Oxide Production<br><br> 
       <table cellspacing="0" cellpadding="0" border="0" id="tttt"> 
        <tbody> 
         <tr> 
          <td><b><font class="pricecolor colors_productprice"><span class="PageText_L483n"><h3><b style="font-size:13px"><span class="saleprice"><font class="text colors_text"><b><span class="PageText_L335n">Sale Price</span>: </b></font></span> <b class="prodPrOr">$34.05 </b></b></h3></span></font></b><br><a class="pricecolor colors_productprice" href="/ShoppingCart.asp?ProductCode=amino%2Dchewables"><b><span class="PageText_L655n"><img class="AddRight" src="/v/vspfiles/assets/images/addtocartsmall.gif"></span></b></a> 
          </td> 
         </tr> 
        </tbody> 
       </table> 
       <br><br> 
       <a onclick="window.open('/help_FreeShipping.asp', 'FreeShipping', 'scrollbars,status,resizable,width=300,height=300');" href="javascript:void(0);"> 
       <img border="0" alt="" src="/v/vspfiles/templates/2007New/images/Icon_FreeShipping.gif" class="vCSS_img_icon_free_shipping"></a> 
      </td> 
      <td valign="top" align="right" id="v65-productdetail-action-wrapper" class="v65-productdetail-options"> 
       <div id="contact"> 
        <img src="/v/vspfiles/assets/images/osw0001_talk_button.jpg"> 
       </div> 
      </td> 
     </tr> 
     <tr> 
      <td colspan="2"> 
       <ul></ul> 
      </td> 
     </tr> 
    </tbody> 
</table> 

回答

1

你应该一个类或ID添加到你要选择做了很多简单的TD 。例如。如果你成功了:

<td class="myText">Build ... </td> 

现在,您可以轻松地选择它(但如果你不能添加类由于某种原因,也有周围的方式 - 它只是做最简单的方法),恕我直言。

$('.myText').html().replace($('.myText').html().match(/^.*/), '<span class="myClass">'+$('.myText').html().match(/^.*/)+'</span>');