在javascript中将图像添加到按钮 [英] add image to button in javascript

查看:106
本文介绍了在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);

您可以修改它.

http://jsfiddle.net/6HdnU/

这篇关于在javascript中将图像添加到按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆