2016-05-05 35 views

回答

0

所以,当你按住鼠标按钮时,你希望它改变样式,然后当你释放它恢复正常?您可以使用jQuery中的mousedownmouseup事件。

基本结构:

("#element").mousedown(function(){ 
    this.css(); 
}); 

("#element").mouseup(function(){ 
    this.css(); 
}); 
0

你需要下面的CSS添加到您的按钮。

<button type="button" class="myBtn">Highlight me when Clicked</button> 
.myBtn:active { 
    background-color: #dd4814; 

} 

查看fiddle。根据您的要求更改css。

+0

谢谢,它帮助我。 –

0

你的HTML:

<input type="button" id="buttonId" value="Button" onclick="showChanges()"/> 

和JS:

<script> 
function showChanges(){ 
    document.getElementById("buttonId").style.backgroundColor ="red"; 
} 
</script> 
1

试试这个

<input type="button" class="button_example" href="#" value="PREVIEW BUTTON"></input> 

.button_example:active{ 
    background:#000; 
} 

http://jsbin.com

相关问题