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 關注
- 1670 瀏覽
添加回答
舉報