我希望我的输入 type=button 仅在按下时更改颜色。例如,如果我有一个白色按钮,我希望它仅在按下时变为绿色,当不再按下时,我希望它返回白色。我怎样才能在 HTML 和 Javascript 中做到这一点?
			
			14164 次
		
3 回答
            5        
        
		
于 2012-08-17T01:46:35.217   回答
    
    
            1        
        
		
对我来说,它只适用于:
<style>
input:active{  background-color:green}
</style>
另一种选择是在鼠标悬停时指定,仅用于按钮:
<style>
input[type=button]:hover{  background-color: #46000D}
<style>
于 2013-05-18T12:07:58.653   回答
    
    
            1        
        
		
普通的 HTML + JavaSctipt:
<input type="button" style="background-color:white" value="Click Me" onmousedown="this.style.background='green'" onmouseup="this.style.background='white'" />
演示:http: //jsfiddle.net/bqjzq/
于 2012-08-17T01:51:51.843   回答