87,907
社区成员
发帖
与我相关
我的任务
分享
$("select:selected").text();//用JQuery
//JS空格事件选取Select项<br />
<br />
<select onkeypress="changeChars(window.event.keyCode,this,'otherFocusId')">
<option value="baoma">宝马</option>
<option value="benchi">奔驰</option>
</select>
<script type="text/javascript">
function changeChars(code, obj, otherFocusId) {
if (code == 32) {
document.getElementById("" + otherFocusId + "").focus();
}
document.getElementById("" + otherFocusId + "").value = obj.value;
}
</script>
<input type="text" id="otherFocusId" />
<!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>
<script>
function spaceEvt(e){
var evt=e||window.event;
if(evt.keyCode=='32')
alert(document.getElementById("sel").options[document.getElementById("sel").options.selectedIndex].text);
}
</script>
</head>
<body onkeyup="spaceEvt(event)">
<select id="sel" style="width:100px;" size="15">
<option value="11">1</option>
<option value="22">2</option>
<option value="33">3</option>
<option value="44">4</option>
<option value="55">5</option>
<option value="66" selected="selected">6</option>
<option value="77">7</option>
<option value="88">8</option>
<option value="99">9</option>
<option value="10">10</option>
</select>
</body>
</html>
写一个小例子挺简单的!