私は多くのデバッグを行いましたが、エラーが発生するようです I try to use "this" in ae2Multi()
.
<html><head>
<title>Custom</title>
<style type="text/css"></style>
<script type="text/javascript">
function ae2(elementName) {
var elementObject;
var elementType = elementName.charAt(0);
if(elementType == "#") {
elementObject = document.getElementById(elementName.substr(1));
} else if(elementType == ".") {
elementObject = document.getElementsByClassName(elementName.substr(1));
} else {
elementObject = document.getElementsByTagName(elementName);
}
return elementObject;
}
function ae2Single() {
this.innerHTML = "singleIsWorking";
}
function ae2Multi() {
alert(this);
for (var i = 0; i < this.length; i++) {
this[i].innerHTML = "it really worked!";
}
}
Element.prototype.ae2Single = ae2Single;
Element.prototype.ae2Multi = ae2Multi;
window.onload = function() {
ae2(".container").ae2Multi();
}
</script></head><body><div id="containerMain">hello world!</div><div class="container">hello again!</div><div class="container">hello yet again!</div></body</html>