1.控件dom

<select name="WebSiteTarget" id="WebSiteTarget" class="w1" onchange="editable2(this);">
<option value="-1">请选择城市</option>
<option>福州</option>
<option>厦门</option>
<option>南平</option>
<option value="0">(自定义输入)</option>
</select>

2.脚本

<script>
function editable2(dom) {
if (dom.value == "0") {
var newvalue = prompt("请输入", "");
if (newvalue) {
addSelected(dom, newvalue, newvalue);
}
}
} function addSelected(fld1, value1, text1) {
if (document.all) {
var Opt = fld1.document.createElement("OPTION");
Opt.text = text1;
Opt.value = value1;
fld1.options.add(Opt);
Opt.selected = true;
} else {
var Opt = new Option(text1, value1, false, false);
Opt.selected = true;
fld1.options[fld1.options.length] = Opt;
}
}
</script>

3.效果

可以添加自定义的Select控件-LMLPHP

05-17 13:19