3 回答

TA贡献1847条经验 获得超7个赞
这就是事件冒泡,当一个元素触发事件后,会逐层上报给父元素、祖父元素……乃至document,也就是说这些元素都会同时触发事件。这种情况下,event.target就是指最初触发事件的那个子元素(就比如你题目中的img),而event.currentTarget才是被冒泡后触发事件的当前元素(比如li)。这也就意味着,当你点击li时,如果点到的是子元素img,则event.target就是img,而event.currentTarget则是li,而当你点到的是li里面除img之外的其他部分时,event.target和event.currentTarget都是li
所以,现在你知道该怎么做啦?就是不要使用event.target,改用event.currentTarget

TA贡献1848条经验 获得超2个赞
ServiceContract(NameSpace="UserInfo")]
public interface IUser
{
[OperationContract]
[WebInvoke(UriTemplate="/AddUser",Method="POST",ResponseFormat=WebMessageFormat.Json,RequestFormat=WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.WrappedRequest)]

TA贡献1810条经验 获得超5个赞
只需要在函数参数中传入$event参数,在函数中使用$event.target就可以获取到了。
具体方法:
[javascript] view plain copy
<input class="unchecked" type="checkbox" ng-model="item.isCustOmized" ng-click="switchCheckBox($event, item.isCustOmized)" />
[javascript] view plain copy
$scope.switchCheckBox = function($event, value) {
// console.log(value)
if (value) {
$($event.target).addClass("checked");
} else {
$($event.target).removeClass("checked");
}
}
- 3 回答
- 0 关注
- 1644 浏览
添加回答
举报