一旦用戶偏好「a」,按鈕顏色會改變,然後一旦用戶釋放「a」按鈕,它應該應該再次改變。一旦按下字母「a」,按鈕只會改變顏色,而不是釋放時。jQuery KeyUp()問題
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>website</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$(document).keyup(function(event) {
if (event.which == 97){
$('.button0 input').css('color', 'rgb(0, 0, 255)');
}
});
$(document).keypress(function(event) {
if (event.which == 97){
$('.button0 input').css('color', 'rgb(128, 0, 0)');
}
});
});
</script>
<style type="text/css">
.button0 input{
position:fixed;
left:41px;
top:12px;
font-family:Arial;
font-size:8px;
font-weight:normal;
}
</style>
<body>
<div class="button0">
<input type="button" style="width: 303px;height: 165px;" value="Button"/>
</div>
</body>
</html>
爲什麼你使用'keypress'和'keyup'而不是'keydown'和'keyup'? – nnnnnn