Javascript 在jQuery中从TD获取innerHTML
您好,我使用的是Sharepoint 2010页面,其中的HTML snipet具有以下结构:Javascript 在jQuery中从TD获取innerHTML,javascript,jquery,client-side,Javascript,Jquery,Client Side,您好,我使用的是Sharepoint 2010页面,其中的HTML snipet具有以下结构: <tr> <td></td> <td class="ms-vb2"></td> <td class="ms-vb2"></td> <td class="ms-vb2"></td> <td class="ms-vb2"></td> <td cl
<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>
总和=72
总和=66
现在我想从var中的TD标记中获取值72和66,以便在客户端脚本中使用这些值
TD的“Sum=”部分不应更改。表的ID是由sharepoint随机生成的,所以我也不能用它做任何事情
请帮忙
谢谢
$(".ms-vb2 b").each(function(td) {
var s = td.hmtl().replace("Sum= ", "");
$("body").append(s);
});
这是。试试下面的方法,它会对你有所帮助 小提琴:
以下是解决方案-我花了时间生成相同的解决方案:) 谢谢
$('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= ",""));
});
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
}
});