Javascript 添加事件的功能不起作用
Javascript Function to add Event not working
我刚注意到这个。这有点奇怪,但我不知道我是忘记做某事还是只是做不到。
我正在尝试以这两种不同的方式在元素上添加事件。第一个有效,但第二个无效。请有人通过
(Snippet A)... //这会将事件添加到输入标签并且在大多数浏览器中都能正常工作
for (var j = 0, inp = _T("input");j < inp.length;j++) {
var place, value;
inp[j].classList.contains("inp") ? inp[j].onblur = inp[j].onfocus = function() {
this.placeholder != "" ? (value = this.value, place = this.placeholder, this.placeholder = "", this.value = value) : this.placeholder = place;
this.className.indexOf("swell")>0 ? rC(this, "swell") : aC(this, "swell");
}:0
}
(Snippet B)... //这在任何浏览器中都不起作用,但我需要它来解决兼容性问题
for (var j = 0, inp = _T("input");j < inp.length;j++) {
var place, value;
inp[j].className.indexOf("inp") > 0 ? inp[j].onblur = inp[j].onfocus = function() {
this.placeholder != "" ? (value = this.value, place = this.placeholder, this.placeholder = "", this.value = value) : this.placeholder = place;
this.className.indexOf("swell") > 0 ? rC(this, "swell") : aC(this, "swell");
}:0
}
//_T("input") = document.getElementsByTagName
我正忙于一个严肃的项目,像这样的小问题只会让人沮丧。
indexOf 将 return 0 如果它是第一个元素。因此,如果 "inp" 存在但它是第一部分(元素 0),它将不会大于零。
我刚注意到这个。这有点奇怪,但我不知道我是忘记做某事还是只是做不到。 我正在尝试以这两种不同的方式在元素上添加事件。第一个有效,但第二个无效。请有人通过
(Snippet A)... //这会将事件添加到输入标签并且在大多数浏览器中都能正常工作
for (var j = 0, inp = _T("input");j < inp.length;j++) {
var place, value;
inp[j].classList.contains("inp") ? inp[j].onblur = inp[j].onfocus = function() {
this.placeholder != "" ? (value = this.value, place = this.placeholder, this.placeholder = "", this.value = value) : this.placeholder = place;
this.className.indexOf("swell")>0 ? rC(this, "swell") : aC(this, "swell");
}:0
}
(Snippet B)... //这在任何浏览器中都不起作用,但我需要它来解决兼容性问题
for (var j = 0, inp = _T("input");j < inp.length;j++) {
var place, value;
inp[j].className.indexOf("inp") > 0 ? inp[j].onblur = inp[j].onfocus = function() {
this.placeholder != "" ? (value = this.value, place = this.placeholder, this.placeholder = "", this.value = value) : this.placeholder = place;
this.className.indexOf("swell") > 0 ? rC(this, "swell") : aC(this, "swell");
}:0
}
//_T("input") = document.getElementsByTagName
我正忙于一个严肃的项目,像这样的小问题只会让人沮丧。
indexOf 将 return 0 如果它是第一个元素。因此,如果 "inp" 存在但它是第一部分(元素 0),它将不会大于零。