Javascript 对齐IE中按钮中心的图像

Javascript 对齐IE中按钮中心的图像,javascript,html,css,Javascript,Html,Css,我在一个按钮中放置了一个图像,问题在于Firefox,图像正确对齐,但在IE中,图像移动到了按钮的右角 我尝试了很多方法使它与中心对齐,但没有任何效果。我正在动态创建按钮和图像,并且我已经减小了图像的宽度和高度-这就是它在IE中不正确对齐的原因,但是我不想更改图像和按钮的高度和宽度 下面是我现在使用的代码: var button = document.createElement("button"); button.setAttribute("type","button"); button.set

我在一个按钮中放置了一个图像,问题在于Firefox,图像正确对齐,但在IE中,图像移动到了按钮的右角

我尝试了很多方法使它与中心对齐,但没有任何效果。我正在动态创建按钮和图像,并且我已经减小了图像的宽度和高度-这就是它在IE中不正确对齐的原因,但是我不想更改图像和按钮的高度和宽度

下面是我现在使用的代码:

var button = document.createElement("button");
button.setAttribute("type","button");
button.setAttribute("id","primaryDelTel"+nameCode+telephoneCount);
button.setAttribute("class","greybutton");
button.setAttribute("style","width:20px;height:20px;");
var delButton = document.createElement("img");
delButton.setAttribute("src","/theme/images/deleteButton.png");
delButton.setAttribute("height","10");
delButton.setAttribute("width","9");
button.appendChild(img);
你可以试试这个:

var button = document.createElement("button");
button.setAttribute("type","button");
button.setAttribute("id","primaryDelTel" + nameCode + telephoneCount);
button.setAttribute("class","greybutton");
button.setAttribute("style","width:20px; height:20px; padding:0; position:relative;");
document.body.appendChild(button);

var delButton = document.createElement("img");
delButton.setAttribute("src","/theme/images/deleteButton.png");
delButton.setAttribute("height","10");
delButton.setAttribute("width","10");
delButton.setAttribute("style","position:absolute; top:3px; left:3px;");
button.appendChild(delButton);

下面是一个关于JSFIDLE的示例

您好,您可以提供一个JSFIDLE吗?你目前正在做什么?或当前正在发生的事件的示例屏幕截图。Thankshow在此上传屏幕截图?使用
Prnt Scr
(粘贴到mspaint中)在您喜爱的图像主机上上传并使用此代码
![消息](图像url)