[英]how to change the color of button image on clicking?
Here is my code 这是我的代码
Here i used "hover" of CSS to change the button image font color when mouse pointer is on button image...now i need to change the Image color OR font color when i click on button image... 在这里,当鼠标指针位于按钮图像上时,我使用CSS的“悬停”来更改按钮图像字体颜色...现在,当我单击按钮图像时,我需要更改图像颜色或字体颜色...
So help me to give this requirement to my button image.... 因此,请帮助我将此要求赋予按钮图像...。
CSS code for button image : 按钮图片的CSS代码:
<style>
.button {
border: none;
background: url('images/btn_login.jpg') no-repeat top left;
color:white;
padding: 2px 8px;
}
.button:hover {
border: none;
background: url('images/btn_login.jpg') no-repeat top left;
color:black;
padding: 2px 8px;
}
</style>
HTML code : HTML代码:
<td width="84"><input name="login" class="button" id="" type="submit" value="Login" /></td>
尝试这个
<td width="84"><input name="login" class="button" onclick="this.style.color = 'green';" id="id" type="submit" value="Login" /></td>
Use the following javascript code to change the color of the button
class when clicked: 单击时,使用以下javascript代码更改button
类的颜色:
<td width="84"><input name="login" class="button" onclick="changeColor()" id="id" type="submit" value="Login" /></td>
<script>
function changeColor() {
document.getElementById("id").style.color = "green";
}
</script>
you have 2 selectors: 您有2个选择器:
:active when mouse is down :当鼠标按下时激活
:focus when mouse is released if button keeps the focus. :focus释放鼠标时,如果按钮保持焦点。
<style>
.button {
border: none;
background: url('images/btn_login.jpg') no-repeat top left;
color:white;
padding: 2px 8px;
}
.button:hover {
border: none;
background: url('images/btn_login.jpg') no-repeat top left;
color:black !important;
padding: 2px 8px;
background-color:#F00 !important;
}
</style>
CSS: CSS:
.button {
border: none;
background: url('images/btn_login.jpg') no-repeat top left;
color:white;
padding: 2px 8px;
}
.button:hover {
border: none;
background: url('images/btn_login.jpg') no-repeat top left;
color:black;
padding: 2px 8px;
}
.buttonhover {
border: none;
background: url('images/btn_login.jpg') no-repeat top left;
color:black;
padding: 2px 8px;
}
Jquery: jQuery:
$(".button").on('click',function(){
$(this).removeClass('button');
$(this).addClass('buttonhover');
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.