我希望在点击
之后的行中的div时获取行的内容HTML:
<td class="ms-cellstyle ms-vb2">10</td>
<td class="ms-cellstyle ms-vb2">
<div class="ms-chkmark-container">
<div class="ms-chkmark-container-centerer"><span class="ms-cui-img-16by16 ms-cui-img-cont-float" unselectable="on" style="z-index:0"><img id="2,10,chk" liid="10" shouldanimate="1" lid="{00124E2C-BFCD-4501-8668-EFAF8E6416D2}" tabindex="0" title="Mark task complete." class="js-chkmark ms-chkmark-notcomplete" src="/_catalogs/theme/Themed/626BDBFA/spcommon-B35BB0A9.themedpng?ctag=11" unselectable="on" hascheckmarkhandler="1"></span>
</div>
</div>
</td>
JS:
var itemID = $("div .ms-chkmark-container").click(function () {
var id = $(this).closest("td").prev().html();
console.log(id);
return id;
})
答案 0 :(得分:0)
为什么不直接使用parent()而不是prev()?
var id = $(this).parent().prev().html();
虽然没试过,但应该可以。
您也可以将点击指向td本身并使用$(this)。
答案 1 :(得分:-1)
<td class="ms-cellstyle ms-vb2 itemid">10</td>
<td class="ms-cellstyle ms-vb2">
<div class="ms-chkmark-container">
<div class="ms-chkmark-container-centerer"><span class="ms-cui-img-16by16 ms-cui-img-cont-float" unselectable="on" style="z-index:0"><img id="2,10,chk" liid="10" shouldanimate="1" lid="{00124E2C-BFCD-4501-8668-EFAF8E6416D2}" tabindex="0" title="Mark task complete." class="js-chkmark ms-chkmark-notcomplete" src="/_catalogs/theme/Themed/626BDBFA/spcommon-B35BB0A9.themedpng?ctag=11" unselectable="on" hascheckmarkhandler="1"></span>
</div>
</div>
</td>
("div .ms-chkmark-container").click(function () {
var id=$(this).parent().prev(".itemid").html();
}