最近想到一个问题 就是在键盘给input(text)赋值之前能截取到 input的value 并且阻止后续操作么
上网查了些资料 发现控制字符串都是在 document.getElementById("xxx").value 生成之后才做得操作 怎么样才能在value生成之前截取到输入的值呢?
上网查了些资料 发现控制字符串都是在 document.getElementById("xxx").value 生成之后才做得操作 怎么样才能在value生成之前截取到输入的值呢?
<!doctype html>
<html>
<head>
<meta charset="gb2312" />
<title></title>
<style>
</style>
</head>
<body>
<input id="test" />
<script>
function $(o){return document.getElementById(o)}
$('test').onkeydown = function(e){
e = e || window.event;
alert( e.keyCode ) //验证keyCode
}
</script>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
window.onload=function(){
document.getElementById("test").onkeydown=function(event){
return false;
}
document.getElementById("test2").onkeyup=function(event){
return false;
}
document.getElementById("test3").onkeypress=function(){
return false;
}
}
</script>
</head><body>
<input type="text" id="test" />
<input type="text" id="test2" />
<input type="text" id="test3" />
</body>
</html>
刚才试了一下,keydown和keypress的时候是能截取的但是keyup事件是不行的,貌似已经生成了结贴了 , 谢谢大家