document.createElement is not working in IE8
The document.createElement('a') tag is not working in IE8 in this snippet of code. It works fine in chrome and firefox. When I check through IE, it see开发者_如何学Pythonms as if its the first line of code that's broken.
item = document.createElement('a');
item.setAttribute('id', 'memorize');
item.innerHTML = "<?php echo wzfactory::get_xml('menu_item', 4, $com); ?>";
item.setAttribute('class', 'menu_button');
item.onclick = function() {redirect('memorizor', 'memorize', 0);};
menu_div.appendChild(item);
Does anybody know why this is the case, and if there is a crappy browser workaround? I haven't been able to find the workaround.
Couple of things that might "break" the functionality.. try this instead:
item = document.createElement('a');
item.id = 'memorize';
item.href = "#";
item.innerHTML = "<?php echo wzfactory::get_xml('menu_item', 4, $com); ?>";
item.className 'menu_button';
item.onclick = function() {
redirect('memorizor', 'memorize', 0);
return false;
};
menu_div.appendChild(item);
First, assign the id
directly and not via setAttribute
and second, anchor without href
becomes mere text, not link so you must assign that attribute.
精彩评论