查找和获取特定的行中的JavaScript或php
搜索“” Customer_011111'。 如果找到,则获得第二类内部html +第三类内部html。 打印:110查找和获取特定的行中的JavaScript或php
<td class="small">Text1</td> <td class="small">Customer_011111</td>
<td class="small">10</td>
<td class="small">100</td>
<td class="small">1000</td>
<td class="small">10000</td>
回答:
下面是一个JavaScript版本
var match = 'Customer_011111', firstSibling = null,
secondSibling = null;
window.onload = function(){
var selector = document.querySelectorAll('td');
for (i = 0; i < selector.length; ++i){
if(selector[i].innerHTML == match){
firstSibling = Number(selector[i+1].innerHTML);
secondSibling = Number(selector[i+2].innerHTML);
var answer = document.createElement('div');
answer.innerHTML = firstSibling + secondSibling;
document.body.appendChild(answer);
break;
}
}
}
<table> <tr>
<td class="small">Text1</td>
<td class="small">Customer_011111</td>
<td class="small">10</td>
<td class="small">100</td>
<td class="small">1000</td>
<td class="small">10000</td>
</tr>
</table>
回答:
如果您在项目中拥有jQuery的,那么你可以这样做:
$('.small').each(function(){ if ($(this).html() == 'Customer_011111'){
//this is the found element
var second = $(this).next().next();
var third = second.next();
var secondHtml = second.html();
var thirdHtml = third.html();
}
})
以上是 查找和获取特定的行中的JavaScript或php 的全部内容, 来源链接: utcz.com/qa/257112.html