本文介绍了jQuery KeyUp()问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一旦用户按下a,按钮颜色将会改变,然后一旦用户释放a按钮,它应该再次更改。一旦按下字母a,按钮只会更改颜色,而不是在被释放时。
Once the user preses "a", the button colour will change, then once the user releases the "a" button it should change again. The button only changes colour once the letter "a" has been pressed, not when released.
<!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>
推荐答案
从 for .keypress()
:
所以你需要将 event.which == 97
更改为 event.which == 65
在你的 keyup
处理程序。
So you need to change event.which == 97
to event.which == 65
in your keyup
handler.
这篇关于jQuery KeyUp()问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!