每当我点击跨度时,我想检测我是否包含 img 标签或标签。我怎样才能做到这一点。
<span class="scorecount" id="6" onclick="javascript:changethevalue(this)">
<img src="images/lock.png" width="25px" height="25px">
</span>
<span class="scorecount" id="6" onclick="javascript:changethevalue(this)">
4
</span>
function changethevalue(object) {
console.log($(object).children('img'));
}
输出是当我点击 img
[img,prevObject:jQuery.fn.jQuery.init[1],上下文:span#4.scorecount,选择器:“img”,构造函数:函数,init:函数...]
在 4 上是 [prevObject: jQuery.fn.jQuery.init[1], context: span#2.scorecount, selector: "img", constructor: function, init: function…]