<html>
<head>
<script>
function showinco(){
if(document.getElementById("choosetype").value=="aaa"){
document.getElementById("chooseincome").style.display="";
}
}
var id=1;
function createOption(obj){
var sText=id;
if(obj.value=="0"){
var oOption = document.createElement("option");
obj.options.add(oOption,0);
oOption.Value=sText;
oOption.selected=true;
id++;
}
}
function getValue(obj){
var s=obj.options[obj.selectedIndex].text+String.fromCharCode(event.keyCode);
if(obj.value!="0"){
obj.options[obj.selectedIndex].text=s
}
}
</script> </head>
<body>
<form>
<table>
<tr>
<td>
<select name="choosetype" onChange="showinco(); ">
<option value="">---- </option>
<option value="aaa">yes </option>
<option value="bbb">no </option>
</select>
</td>
<td width="200">
<div id="chooseincome" style="display:none">
<select id="incotype" name="incotype" onChange="createOption(this)" onkeypress="getValue(this)">
<option value="0">------ </option> <!--每次选择时,添加一个option,可直接输入-->
<option value="weco">kkk </option>
</select>
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
<head>
<script>
function showinco(){
if(document.getElementById("choosetype").value=="aaa"){
document.getElementById("chooseincome").style.display="";
}
}
var id=1;
function createOption(obj){
var sText=id;
if(obj.value=="0"){
var oOption = document.createElement("option");
obj.options.add(oOption,0);
oOption.Value=sText;
oOption.selected=true;
id++;
}
}
function getValue(obj){
var s=obj.options[obj.selectedIndex].text+String.fromCharCode(event.keyCode);
if(obj.value!="0"){
obj.options[obj.selectedIndex].text=s
}
}
</script> </head>
<body>
<form>
<table>
<tr>
<td>
<select name="choosetype" onChange="showinco(); ">
<option value="">---- </option>
<option value="aaa">yes </option>
<option value="bbb">no </option>
</select>
</td>
<td width="200">
<div id="chooseincome" style="display:none">
<select id="incotype" name="incotype" onChange="createOption(this)" onkeypress="getValue(this)">
<option value="0">------ </option> <!--每次选择时,添加一个option,可直接输入-->
<option value="weco">kkk </option>
</select>
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>可输入的下拉列表.html</title>
<script type="text/javascript" src="inpect.js"></script>
<script type="text/javascript">
/***Date:2007/12/18****/
window.inpect = function(parent ,width){ //基本属性 public
this.parent = (typeof parent == 'undefined')?document.body:parent;
this.width = parseInt((typeof width == 'undefined')?130:width); //获取对象方法 private
var $ = function(el){
return (typeof el == 'object')?el:document.getElementById(el);
};
//初始化控件 private
this.init = function(){
var strHTML = "<div style='position:absolute;z-index:1;clip:rect(3 280 20 "+ this.width +");'>"
+ "<select id='sel' style='width:"+ (this.width+17) +"'></select>"
+ "</div>"
+ "<div style='position:absolute;z-index:2;'>"
+ "<input hideValue='' id='inp' style='width:"+ (this.width+17) +"; height:20;'>"
+ "</div>";
this.parent.innerHTML = strHTML;
};this.init();
//选中赋值 anonymous
$("sel").onchange = function(){
$("inp").value = this.options[this.selectedIndex].text;
$("inp").hideValue = this.value;
};
//添加option public
this.addOption = function(text ,value){
var op= new Option(text ,value);
$("sel").options.add(op);
}; //给控件赋值 public
this.setValue = function(value){
$("inp").value = selOption(value);
$("inp").hideValue = value;
}; //获取控件值 public
this.getValue = function(){
return $("inp").hideValue;
}; //选中控件 private
var selOption = function(value){
if($("sel").options.length != 'undefined'){
for(var i=0;i<$("sel").options.length;i++){
if($("sel").options[i].value == value){
$("sel").options[i].selected = true;
return $("sel").options[i].text;
}
}
}
};
};
window.onload = function(){
window.ipt = new window.inpect(document.all("aaa"));
ipt.addOption("aa" ,"11");
ipt.addOption("bb" ,"22");
ipt.addOption("cc" ,"33");
};</script>
</head>
<body>
<div id="aaa" style='position:absolute;z-index:1;left:200'>
</div>
<input type="button" value="设置" onclick="ipt.setValue('22')">
<input type="button" value="获取" onclick="alert(ipt.getValue())">
</body>
</html>