我正在处理的代码:
<table>
<tr>
<td>floor area</td>
<td>60 m²</td>
</tr>
<tr>
<td>floor area unit</td>
<td>30 m²</td>
</tr>
<tr>
<td>floor</td>
<td>1</td>
</tr>
<tr>
<td>rooms</td>
<td>2</td>
</tr>
<tr>
<td>bathroom</td>
<td>1</td>
</tr>
</table>
到目前为止,这是我的代码,以获得楼面面积值
var i = 0;
$('tr').each(function(){
if (i==1){
var floorarea= $(this).find('td')[2].text();
dataparse.floorarea = floorarea;
} i++;
});
我是Jquery的新手, 1.我的问题是我怎么才能得到这个价值60平方米的价值? 2.我怎样才能得到所有的td值? 对我有什么想法?我需要一个建议。
答案 0 :(得分:0)
您可以尝试:Demo
Error: Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
答案 1 :(得分:0)
你也可以这样做
$('tr').each(function() {
var tdname = $(this).find("td:eq(0)").text();
var tdvalue = $(this).find("td:eq(1)").text();
if(tdname=="floor area"){
alert(tdvalue);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>floor area</td>
<td>60 m²</td>
</tr>
<tr>
<td>floor area unit</td>
<td>30 m²</td>
</tr>
<tr>
<td>floor</td>
<td>1</td>
</tr>
<tr>
<td>rooms</td>
<td>2</td>
</tr>
<tr>
<td>bathroom</td>
<td>1</td>
</tr>
</table>