for the select element, if use click the left arrow key, then the select index will be changed, I want to cancel this default event, how can I do?
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<select id="select" onkeypress="test(event)">
<option value="aaa">a</option>
<option value="bbb">b</option>
<option value="ccc">c</option>
</select>
<script type="text/javascript">
function test(event) {
event = (event || window.event);
var key = (event.keyCode || event.charCode);
if(key == 37 || key == 39) {
event.stopPropagation();
event.preventDefault();
return false;
}
}
</script>
</body>
</html>
Comment