この記事では、JSに入力関数を備えた選択されたドロップダウンボックスを実装する方法について説明します。参照のためにそれを共有してください。特定の実装方法は次のとおりです。
実装方法1
次のようにコードをコピーします:<html>
<head>
<Meta http-equiv = 'content-type' content = 'text/html; charset = gb2312 '>
<Title> JSは、入力可能なドロップダウンボックスを実装しています</title>
</head>
<body>
<div style = "position:relative;">
<Span style = "マージン左:100px;幅:18px;オーバーフロー:hidden;">
<onchange = "this.parentnode.nextsibling.value = this.value">を選択します
<オプション値= "ドイツ">ドイツ</option>
<オプション値= "ノルウェー">ノルウェー</option>
<オプション値= "スイス">スイス</option>
</select> </span> <入力name = "box">
</div>
</body>
</html>
実装方法2
コードコードを次のようにコピーします。<選択id = "select" onkeydown = "select.del(this、event)" onkeypress = "select.write(this、event)">
<オプション値= ""> </option>
<オプション値= "aaa"> aaa </option>
<オプション値= "bbb"> bbb </option>
<オプション値= "ccc"> ccc </option>
</select>
<入力型= "button" value = "get selection value" id = "test" onclick = "test();"/>
<スクリプト>
var select = {
del:function(obj、e){
if((e.keycode || e.which || e.charcode)== 8){
var opt = obj.options [0];
opt.text = opt.value = opt.value.substring(0、opt.value.length> 0?opt.value.length-1:0);
}
}、
書き込み:function(obj、e){
if((e.keycode || e.which || e.charcode)== 8)return;
var opt = obj.options [0];
opt.selected = "selected";
opt.text = opt.value += string.fromcharcode(e.charcode || e.
}
}
function test(){
alert(document.getElementById( "select")。value);
}
< /script> <br />
この記事がみんなのJavaScriptプログラミングに役立つことを願っています。