日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

select选择框变得可以输入、编辑

發(fā)布時(shí)間:2025/3/21 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 select选择框变得可以输入、编辑 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

?

一、可編輯的select

按回車鍵輸入新內(nèi)容,按DEL刪除選中內(nèi)容<br>
<body bgcolor="#fef4d9" οnlοad="s1.focus();">
<script language="JavaScript">
<!--
function catch_keydown(sel)
{
switch(event.keyCode)
{
?? case 13:
??? //Enter;
??? sel.options[sel.length] = new Option("","",false,true);
??? event.returnValue = false;
??? break;
?? case 27:
??? //Esc;
??? alert("text:" + sel.options[sel.selectedIndex].text + ", value:" + sel.options[sel.selectedIndex].value + ";");
??? event.returnValue = false;
??? break;
?? case 46:
??? //Delete;
??? if(confirm("刪除當(dāng)前選項(xiàng)!?"))
??? {
???? sel.options[sel.selectedIndex] = null;
???? if(sel.length>0)
???? {
????? sel.options[0].selected = true;
???? }
??? }
??? event.returnValue = false;
??? break;
?? case 8:
??? //Back Space;
??? var s = sel.options[sel.selectedIndex].text;
??? sel.options[sel.selectedIndex].text = s.substr(0,s.length-1);
??? event.returnValue = false;
??? break;
}

}
function catch_press(sel)
{
sel.options[sel.selectedIndex].text = sel.options[sel.selectedIndex].text + String.fromCharCode(event.keyCode);
event.returnValue = false;
}
//-->
</script>
<select name=s1 οnkeydοwn="catch_keydown(this);" οnkeypress="catch_press(this);" style="font-size:12px;"><option>-12121212121212</option><option>232323232323</option><option>343434343434</option><option>45454545454545</option><option>565656565656</option></select>

?

二、可輸入:

<html>
<head>
<title>助記碼的select選擇完美方案</title>
</head>
<script>

var addressName=new Array("沈陽(yáng)","北京","大連","撫順","天津","上海");
var addressHelpCode=new Array("sy","bj","dl","fs","tj","sh");
var getSelectHelpCode=document.getElementsByName("selectHelpCode");

function init(){
?? with(getSelectHelpCode[0]){
??? length=addressName.length;
??? for(var i=0;i<length;i++){
???? options[i].value=addressHelpCode[i];
???? options[i].text=addressName[i];
??? }
?? }
}

function writeSelect(obj){
?? obj.options[obj.selectedIndex].text=obj.options[obj.selectedIndex].text + String.fromCharCode(event.keyCode);
?? event.returnValue=false;
}

function catch_keydown(sel)
{
?? switch(event.keyCode)
?? {
??? case 46:
???? //delete
???? sel.options[sel.selectedIndex].text ="";
???? event.returnValue = false;
???? break;
??? case 8:
???? //Back Space;
???? var s = sel.options[sel.selectedIndex].text;
???? sel.options[sel.selectedIndex].text = s.substr(0,s.length-1);
???? event.returnValue = false;
???? break;
??? case 13:
???? //Enter;
???? vertiyt(sel)
???? event.returnValue = false;
???? break;
?? }
??
}

function vertiyt(obj){
????? var yy=false;
?? var jj=-1;
?? with(obj){
??? for(var i=0;i<addressName.length;i++){
???? var selectedValue=options[selectedIndex].value;
???? var selectedText=options[selectedIndex].text;
???? if(addressName[i]==selectedText||addressHelpCode[i]==selectedText){
????? yy=true;
????? jj=i;
???? }
??? }
?? }
?? if(yy==true){
??? init();
??? obj.options[jj].selected=true;
?? }else{
??? init();
??? alert("沒(méi)有/""+selectedText+"/"這個(gè)地點(diǎn)或是助記碼!!");
?? }
}


</script>
<body οnlοad="init()">
<select name="selectHelpCode" onBlur="vertiyt(this)" οnkeydοwn="catch_keydown(this)" οnkeypress="writeSelect(this)"><option>--</option></select>
<br>
讓select變得可以輸入,并且可以驗(yàn)證。
<br>
這個(gè)功能是我在一個(gè)項(xiàng)目中所用到的。
<br>
希望對(duì)大家有用!
</body>
</html>

?

?

?

?

<script>

function pp(){

unitid.options[9]=new Option(ok=(unitid.options[9])?unitid.options[9].innerText+String.fromCharCode(event.keyCode):String.fromCharCode(event.keyCode),"client")

unitid.selectedIndex=9;

}

?

function edit(){

if(unitid.options[9]){

if(event.keyCode==8){

var str=unitid.options[9].innerText;

var len=str.length;

unitid.options[9].innerText=str.substring(0,len-1);

if(unitid.options[9].innerText=="")unitid.remove(9);

}

if(event.keyCode==13)return false;

if(event.keyCode==32){

unitid.options[9].innerText+=" ";

?

}

}

}

</script>

<select id=unitid οnkeypress=pp() οnkeyup="edit()">

<option> </option>

<option>個(gè)</option>

<option>件</option>

<option>盒</option>

<option>箱</option>

<option>雙</option>

<option>條</option>

<option>瓶</option>

<option>罐</option>

</select>

?

?

?

?

?

?

?

  • <script?language="javascript">??
  • ????function?changeF()??
  • ????{??
  • ???????document.getElementById('makeupCo').value=??
  • ???????document.getElementById('makeupCoSe').options[document.getElementById('makeupCoSe').selectedIndex].value;??
  • ????}??
  • </script>??
  • ??
  • <span?style="position:absolute;border:1pt?solid?#c1c1c1;overflow:hidden;width:188px;??
  • ????height:19px;clip:rect(-1px?190px?190px?170px);">??
  • <select?name="makeupCoSe"?id="makeupCoSe"?style="width:190px;height:20px;margin:-2px;"?onChange="changeF();">??
  • ????<option?id='1'?value='java'>java</option>??
  • ????<option?id='2'?value='c++'>c++</option>??
  • ????<option?id='3'?value='python'>python</option>??
  • ????<OPTION?id="99999"?VALUE=""?SELECTED>??
  • </select>??
  • </span>??
  • <span?style="position:absolute;border-top:1pt?solid?#c1c1c1;border-left:1pt???
  • ????solid?#c1c1c1;border-bottom:1pt?solid?#c1c1c1;width:170px;height:19px;">??
  • ????<input?type="text"?name="makeupCo"?id="makeupCo"?value="請(qǐng)選擇或輸入"?style="width:170px;height:15px;border:0pt;">??
  • </span>??



  • ?

總結(jié)

以上是生活随笔為你收集整理的select选择框变得可以输入、编辑的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。