<!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=utf-8" />
<title>无标题文档</title>
</head><body>
<input type="text" name="textfield" id="tex" />
<input type="submit" name="button" id="but" value="Backspace" />
</body>
</html>现在页面上有个文本框ID tex 按钮 but 我现在想.每当我单击按钮的时候,文本框tex的内容撤销一个.
用keyCode 具体应该怎么实现呢.
<!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=utf-8" />
<title>无标题文档</title>
</head>
<script>
function bk(){
var v = document.getElementById("tex").value;
document.getElementById("tex").value = v.substr(0, v.length-1);
}
</script>
<body>
<input type="text" name="textfield" id="tex" />
<input type="button" name="button" id="but" value="Backspace" onclick="bk();"/>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<script language="javascript" type="text/javascript">
function doit(id)
{
var o=document.getElementById(id);
o.value=o.value.substr(0,o.value.length-1);
}
</script>
<body>
<input type="text" name="textfield" id="tex" />
<input type="button" name="button" id="but" value="Backspace" onclick="javascript:doit('tex');" />
</body>
</html>