在javascript中将图像添加到按钮
我已经在javascript中创建了一个按钮,但我想使用图像代替按钮来显示文本,但是我还没有找到一种方法来做到这一点.到目前为止,由于某些原因,我所引用的资源对我而言无效.到目前为止,我的情况如下
I have created a button in javascript and I would like to use an image for the button instead of text, but I have not yet found a way to do this. So far the sources I have referenced are not working for me for some reason. What I have so far is as follows
JavaScript
var sb=doc.createElement('input');
sb.type='button';
//sb.value='Find';
sb.src = "url(/Resources/Icons/appbar.next.rest.png)";
sb.style.height='100%';
//sb.style.width='20%';
我的图像位于项目中的目录/Resources/Icons/appbar.next.rest.png
中.有人可以向我指出正确使用按钮图像的正确方向吗?我是javascript新手,所以任何链接,代码或说明都将不胜感激!
where my image is locoated in the directory /Resources/Icons/appbar.next.rest.png
in my project. Can someone point me in the right direction as to how to properly use an image for a button? I am new to javascript so any links, code, or directions would be greatly appreciated!
要将图像添加到按钮,您可以将输入类型从按钮更改为图像:
for adding image to button you can change type of input from button to image:
var body = document.getElementsByTagName("body")[0];
var s = document.createElement("input");
s.src = "http://www.gravatar.com/avatar/a4d1ef03af32c9db6ee014c3eb11bdf6?s=32&d=identicon&r=PG";
s.type = "image";
body.appendChild(s);
您可以修改它.