表上的jQuery-.children()不是函数
这就是HTML:表上的jQuery-.children()不是函数,jquery,Jquery,这就是HTML: <table class="table"> <tr> <th>Doober durr</th> <th>Skippi doober</th> <th>Doober duck</th> <th>Doober McD</th> </tr> <tr>
<table class="table">
<tr>
<th>Doober durr</th>
<th>Skippi doober</th>
<th>Doober duck</th>
<th>Doober McD</th>
</tr>
<tr>
<td>
<input type="text" class="form-control" name="v6" placeholder="Mæling 1" />
</td>
<td>
<input type="text" class="form-control" name="v9" placeholder="Mæling 1" />
</td>
<td>
<input type="text" class="form-control" name="v12" placeholder="Mæling 1" />
</td>
<td>
<input type="text" class="form-control" name="v15" placeholder="Mæling 1" />
</td>
</tr>
</table>
<button style="float:right;" class="btn btn-primary" id="calc"><span class="glyphicon glyphicon-cloud-download"></span> REIKNA</button>
返回表,但当我尝试调用表上的.children()
时,它会说它不是函数。这是因为$(this).sibles()[0]
返回表的dom对象,而不是jquery对象。您可以将表选择器作为参数传递给sibles方法,以获取表的jquery对象:
$("#calc").click(function () {
console.log($(this).siblings('table').children());
});
这是因为$(this).sibbines()[0]
返回表的dom对象,而不是jquery对象。您可以将表选择器作为参数传递给sibbines方法,以获取表的jquery对象:
$("#calc").click(function () {
console.log($(this).siblings('table').children());
});
问题是$(this).siblines()[0]
返回一个dom元素引用,因此它无法访问jQuery方法
因此,如果您想通过索引访问元素,那么使用.eq(index),它将在所述索引处返回对元素的jQuery对象引用
$(this).siblings().eq(0).children();
问题是$(this).siblines()[0]
返回一个dom元素引用,因此它无法访问jQuery方法
因此,如果您想通过索引访问元素,那么使用.eq(index),它将在所述索引处返回对元素的jQuery对象引用
$(this).siblings().eq(0).children();
尝试使用.prev()
尝试使用.prev()
您应该使用$($(this).sides()[0]).children()
,因为您编写的方式是得到表的DOM对象,而不是jQuery对象。您应该使用$($(this.sides()[0]).children()
,因为您编写的方式是得到表的DOM对象,而不是jQuery对象。$(this).sides()[0]
是一个DOM元素。您可以使用$(this).sides().eq(0).children()
或使用DOM元素获取jQ对象,但它有点难看
var domEl = $(this).siblings()[0];
var $jQEl = $(domEl);
var $children = $jQEl.children();
良好实践:在jQ对象前面加上$。$(this).sides()[0]
是一个DOM元素。您可以使用$(this).sides().eq(0).children()
或使用DOM元素获取jQ对象,但这有点难看
var domEl = $(this).siblings()[0];
var $jQEl = $(domEl);
var $children = $jQEl.children();
良好实践:在jQ对象前面加上$。@Firkamon:loady it help:)@Firkamon:loady it help:)这也是一个优雅的解决方案,在jQuery包装器中再次包装DOM元素<@Razvan Dumitru建议的code>$(this).sibbins().eq(0).children())甚至更好。这也是一个优雅的解决方案,在jQuery包装器中再次包装DOM元素<@Razvan Dumitru建议的code>$(this).sibbins().eq(0).children())甚至更好。