iframe:父级有下拉框,点击iframe里面时下拉框不收起
JS
var IframeOnClick = { resolution: 200, iframes: [], interval: null, Iframe: function() { this.element = arguments[0]; this.cb = arguments[1]; this.hasTracked = false; }, track: function(element, cb) { this.iframes.push(new this.Iframe(element, cb)); if (!this.interval) { var _this = this; this.interval = setInterval(function() { _this.checkClick(); }, this.resolution); } }, checkClick: function() { if (document.activeElement) { var activeElement = document.activeElement; for (var i in this.iframes) { if (activeElement === this.iframes[i].element) { // user is in this Iframe if (this.iframes[i].hasTracked == false) { this.iframes[i].cb.apply(window, []); this.iframes[i].hasTracked = true; } } else { this.iframes[i].hasTracked = false; } } } } };
调用
IframeOnClick.track(document.getElementById("iFrame"), function() {
alert('a click');
})
转自: http://blog.csdn.net/sjzs5590/article/details/16623529
====================================================================================
原网址:https://blog.csdn.net/KevinwuwenboA/article/details/53817567?utm_source=blogxgwz0

浙公网安备 33010602011771号