首页 > 网站 > WEB开发 > 正文

让Select框也可以输入自己想输入的内容

2024-04-27 13:57:50
字体:
来源:转载
供稿:网友

<!-- 把下面代码加到<body>区域中 -->
<script>
function pp(){
se.options[2]=new Option(ok=(se.options[2])?se.options[2].innerText+String.fromCharCode(event.keyCode):String.fromCharCode(event.keyCode),"client")
se.selectedIndex=2;
}

function edit(){
if(se.options[2]){
if(event.keyCode==8){
var str=se.options[2].innerText;
var len=str.length;
se.options[2].innerText=str.substring(0,len-1);
if(se.options[2].innerText=="")se.remove(2);
}
if(event.keyCode==13)return false;
if(event.keyCode==32){
se.options[2].innerText+=" ";

}
}
}
</script>
<select id=se onkeyPRess=pp() onkeyup="edit()">
<option>测试程序</option>
<option>javascript</option>
</select>

也可以直接输入字符


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表