[英]Access inline event object function body without 'function' constructor javascript
我正在使用jQuery過濾一堆對象,並且我想訪問事件的函數主體而沒有附加函數構造函數。 我會告訴你我的意思:
$('li').filter(function(){
return this.onmouseout !== null;
})
.each(function(){
console.log(this.onmouseout);
});
得到的返回是:
function onmouseout(event) {
GoodSearchBadgeHideMenu('120');
}
我想退貨的是:
GoodSearchBadgeHideMenu('120');
\\notice the absence of 'function onmouseout(event)' and closing bracket
我確定我可以使用String.replace()
輕松解析它,但是我想知道函數主體是否可以在元素屬性或事件對象的某個位置訪問。
謝謝
由於要將處理程序作為元素屬性附加,因此可以使用.getAttribute()
來檢索設置的主體。
this.getAttribute("onmouseout");
所以...
$('li').filter(function(){
return this.onmouseout !== null;
})
.each(function(){
console.log(this.getAttribute("onmouseout"));
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.