再次使用我的框架。想要创建一种让元素闪烁的方法。我需要在方法内设置间隔。所以我认为这可能有效:
var optionalSelector = "$";
(function() {
(this[arguments[0]] = function constructor(input) {
if (!(this instanceof constructor)) { return new constructor(input); }
this.elm = document.getElementById(input);
}).prototype = {
blink: function() {
function changeDisplay() {
if (this.elm.style.display != "none") {
this.elm.style.display = "none";
} else {
this.elm.style.display = "block";
}
}
setInterval(changeDisplay, 1000);
},
};
})(optionalSelector);
并调用方法$("anElmId").blink();
但事实并非如此。方法内部的另一个函数,还有一个间隔。我想这两个把事情搞砸了。就像它不认识一样this.elm
。由于我是新手,我无法找到解决此问题的方法。有任何想法吗?