2013-04-26 51 views
0

嗨,我使用SharePoint 2010的頁面,在這裏我有HTML snipet結構如下:jQuery中從TD抓取的innerHTML

<tr> 
    <td></td> 
    <td class="ms-vb2"></td> 
    <td class="ms-vb2"></td> 
    <td class="ms-vb2"></td> 
    <td class="ms-vb2"></td> 
    <td class="ms-vb2"><nobr><b>Sum= 72</b></nobr></td> 
    <td class="ms-vb2"><nobr><b>Sum= 66</b></nobr></td> 
</tr> 

現在我想從TD標籤值72和66在var中,以便我可以在客戶端腳本中使用這些值。

TD的「Sum =」部分不應該改變。表格的ID是由Sharepoint隨機生成的,所以我也無法做任何事情。

請幫忙。

感謝,

回答

0

這裏是解決方案 - 花時間讓我產生相同.. :)

var arrValue = ""; 
    $('td.ms-vb2').filter(function (i) { 
     if ($(this).html().indexOf('Sum=') > 0) { 

      mystring = $(this).html(); 
      var result = /\d+(?:\.\d+)?/.exec(mystring); 
      //console.log(arrValue) 
      arrValue = result[0] + "," + arrValue 
     } 
    }); 

謝謝

1
$(".ms-vb2 b").each(function(td) { 
    var s = td.hmtl().replace("Sum= ", ""); 
    $("body").append(s); 
}); 

這裏的the working fiddle

0

嘗試像下面,它會幫助你..

小提琴:http://jsfiddle.net/RYh7U/150/

$('td.ms-vb2').each(function() {  
    var value = $(this).text(); 
    if(value !="") 
    alert(value); 
    //If you want to replace the Sum= in Text then try the below code 
    $(this).text($(this).text().replace("Sum= ","")); 
});