<form action='./index.php' method='post' class='form'>
<table>
<tr>
<td>$error</td>
</tr>
<tr>
<td>Username:</td>
<td><input type='text' name='user' /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='password' /></td>
</tr>
<tr>
<td></td>
<td><input type='image' src='./images/loginbtn.jpg' name='loginbtn' value='Login' alt='Submit Form'/></td>
</tr>
</table>
</form>
上面的代码是代码从我的(工作在进行中)网站。我使用"image"输入类型,因为它允许我使用图像作为按钮。我在这里遇到的问题是,放一些代码让我可以放另一个图像当我把鼠标放在它上面的时候。这段代码包含在PHP标签中,并设置为变量"$form"。这样我就可以回显它并轻松地运行其他PHP代码。
是否有任何CSS,我可以使用在另一个图片,当我的鼠标在按钮上?我是不是把事情弄得比看起来更复杂了?
对于原生javascript,您可以按照以下示例使用onmouseover
:
很抱歉用了这么长的图片url,希望没有混淆。
编辑
CSS: http://jsfiddle.net/dZ2qL/使用hover
更改背景图像。
2日编辑
http://jsfiddle.net/dZ2qL/3/使用<div>
代替<input>
,并在css中添加一些行
background-color:transparent;
border: 0px solid;
看看这个>> fiddler <<
下面是一个简短的jquery代码演示:
首先你需要包含jquery
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
则包含以下代码:
<script>
$(document).ready(function() {
$("#test").hover(
function () {
$(this).attr('src','http://www.seobook.com/images/smallfish.jpg');
},
function () {
$(this).attr('src','http://www.google.com/images/srpr/logo4w.png');
}
);
});
</script>
和在你的html中,你设置id
或class
到你的元素(它必须与示例脚本中的一个相同,值是test
在我的例子中。
<input id="test" type='image' src='http://www.google.com/images/srpr/logo4w.png' name='loginbtn' value='Login' alt='Submit Form'/>