在php中的图像按钮

时间:2013-08-13 06:12:12

标签: php html

我正在尝试将图像用作按钮:

<button name="foo" type="button" value="bar" onclick="AjaxResponse()" > <img src="img.png"> </button>

 <button name="foo" type="button" value="bar" onclick="AjaxResponse()" img src="img.png" /> 

两者都不显示带图像的按钮。它只显示小图标,在点击时执行正确的操作。但为什么图像无法看到?

5 个答案:

答案 0 :(得分:2)

正确指定widthheight。赞

<img src="something" width=200 height=200>

否则使用div标签在CSS的帮助下创建自定义按钮。

通过这个,你可以得到一些想法Click here

答案 1 :(得分:1)

不需要PHP,这在您的HTML部分中,如果没有CSS,您就无法使用:

<input type="image" ...

了解更多内容,请阅读以下链接:Input Types

或者看看CSS:background

答案 2 :(得分:1)

只需使用<img>标记并向其添加onClick

<img src="img.png" onclick="AjaxResponse()" />

此外,您可以根据图片的尺寸设置宽度和高度:

<img src="img.png" onclick="AjaxResponse()" width="100" height="100" />

但是,CSS background-image属性可能是最佳解决方案。在那里,您还可以调整widthheight

答案 3 :(得分:1)

<input type="image" src="FILEPATH" onclick="AjaxResponse()" name="foo" id="button" value="bar">

答案 4 :(得分:1)

如果你不想使用css,你可以使用这样的输入,

input type="image" src="img.png" name="foo" type="button" alt="bar" onclick="AjaxResponse()"