Generalize support for events in Dom element maker
This commit is contained in:
parent
0b7fcfe36b
commit
5bb76dbe9b
1 changed files with 6 additions and 4 deletions
|
@ -22,13 +22,15 @@ function make(tag, properties, children) {
|
||||||
case "maxlength":
|
case "maxlength":
|
||||||
e.setAttribute("maxlength", value);
|
e.setAttribute("maxlength", value);
|
||||||
break;
|
break;
|
||||||
case "onClick":
|
|
||||||
e.addEventListener("click", value);
|
|
||||||
break;;
|
|
||||||
default:
|
default:
|
||||||
|
var matched = key.match(/on([A-Z]\w+)/);
|
||||||
|
if(matched) {
|
||||||
|
e.addEventListener(matched[1].toLowerCase(), value);
|
||||||
|
} else {
|
||||||
e[key] = value;
|
e[key] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for(var i = 0; i < children.length; i++) {
|
for(var i = 0; i < children.length; i++) {
|
||||||
e.appendChild(children[i]);
|
e.appendChild(children[i]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue