Eben
07-24-2009, 07:01 PM
that suppose to bind onclick and change the backgroung color,
this.style.backgroundColor doesnt work with IE, any solution?
<script type="text/javascript">
var els = document.getElementsByTagName('input');
for (i = 0; i < els.length; i++) {
var el = els[i];
if (el.addEventListener) {
el.addEventListener ("click",changeBG,false);
} else if (el.attachEvent) {
el.attachEvent ("onclick",changeBG);
}
}
function changeBG() {
this.style.backgroundColor = 'red';
}
</script>
this.style.backgroundColor doesnt work with IE, any solution?
<script type="text/javascript">
var els = document.getElementsByTagName('input');
for (i = 0; i < els.length; i++) {
var el = els[i];
if (el.addEventListener) {
el.addEventListener ("click",changeBG,false);
} else if (el.attachEvent) {
el.attachEvent ("onclick",changeBG);
}
}
function changeBG() {
this.style.backgroundColor = 'red';
}
</script>