2012-12-03 63 views
1
不工作

我的网址为javascript函数中铬工作,但在IE8

http://somain.com/test.php?id=1&mview=5

登录后上面的网址显示选择名称和图像。我们必须点击添加新条目按钮来添加选择图像,并删除只是我们必须点击删除按钮。但删除按钮和文件上传部分工作正常铬,并在IE 8不工作。

我用一个JavaScript函数添加图像的选择。但是,所有的JS功能工作正常,在Chrome,但它不是在IE 8的工作。这是删除文件上传部分

function addnewchoice(val) 
{ 
var remove = document.createElement("input"); 
remove.setAttribute("type", "button"); 
remove.setAttribute("value", "Remove"); 
remove.setAttribute("onclick", "Remover("+ val +")"); 
remove.setAttribute("class", "removechoice"); 
remove.setAttribute("name", removename); 
} 

function Remover(idval) 
{ 
document.forms['choiceadd']['imageshow'+idval].style.display="none"; 
document.forms['choiceadd']['choicefile'+idval].style.display="none"; 
document.getElementById('fileuploadover'+idval).style.display="none"; 
document.forms['choiceadd']['choicename'+idval].style.display="none"; 
document.forms['choiceadd']['choicename'+idval].value=""; 
document.forms['choiceadd']['remove'+idval].style.display="none"; 
document.getElementById('br'+idval).style.display="none"; 
} 

请人帮我解决这个问题的简单的编码。非常感谢你的阅读和帮助我解决这个问题

回答

3

根据这里的第一个答案 - IE not allowing onClick event on dynamically created DOM 'a' element - 当动态更改元素的onclick属性时,IE8不会自动绑定点击事件处理程序。也就是说,您正在使用HTML设置标记的onclick属性,但浏览器不会将该属性转换为实际的事件处理程序。

尝试

var removeFunc = function() { Remover(val) }; 
if (!remove.addEventListener) //Old IE 
    remove.attachEvent("onclick", removeFunc); 
else //Other browsers 
    remove.addEventListener("click", removeFunc); 

这实际上直接结合的Click事件处理程序,而不是预期的是,浏览器将通过结合其反应设置属性替换

remove.setAttribute("onclick", "Remover("+ val +")"); 

+2

IE8不支持'addEventListener' –

+1

我只是意识到我自己,更新! – AmericanUmlaut

+1

是的。它对我来说工作得很好。非常感谢。 – Rithu

相关问题