----我怎能在别人的苦难面前转过脸去----
[CODE]
<input type="text" size="12" name="opt_value"><input type="button" value="添加" onclick="addopt('opt_value')">
<br>
<select name="opt">
</select>
<script>
function addopt(obj)
{
var b=document.getElementById(obj).value;
var d=document.getElementById("opt");
if (b=="")
{
alert("请输入选项!");
document.getElementById(obj).focus();
return;
}
for(i=0;i<d.length;i++)
{
var value=d.options[i].value;
if(b==value)
{
alert("已经存在这个选项!");
return;
}
}var c=new Option(b,b);
d.add(c);
}
</script>
[/CODE]
[此贴子已经被作者于2006-4-28 20:06:15编辑过]
[CODE]<script language="JavaScript">
<!-- Hide
function test1() {
if (document.form1.select.value == "其他")
document.form1.text1.disabled=false
else
document.form1.text1.disabled=true
}
// -->
</script>
<form id="form1" name="form1" method="post" action="">
<select name="select" onchange="test1()">
<option selected="selected">请选择</option>
<option value="111">111</option>
<option value="222">222</option>
<option value="其他">其他</option>
</select>
<input type="text" name="text1" disabled>
</form>[/CODE]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
<!--
body{margin:30px; font-size:12px}
td{ font-size:12px}
.inputText {
background-image: url(http://toumh.4888.net/UpSel.jpg);
background-repeat: no-repeat;
background-position: right center;
padding-right:18px;
background-attachment: fixed;
margin-right: 18px;
width:181px
}
.SelBg {
color: #FFFFFF;
background-color: #0A246A;
}
.table {
}
#Layer1 {
position:absolute;
width:200px;
height:100px;
z-index:2;
overflow: auto;
background-color: #FFFFFF;
border-top-width: 2px;
border-right-width: 2px;
border-bottom-width: 2px;
border-left-width: 2px;
border-top-style: ridge;
border-right-style: inset;
border-bottom-style: inset;
border-left-style: ridge;
border-top-color: #D4D0C8;
border-right-color: #D4D0C8;
border-bottom-color: #D4D0C8;
border-left-color: #D4D0C8;
}
#Layer2 {
position:absolute;
width:181px;
height:14px;
z-index:2;
overflow: hidden;
}
-->
</style>
<script language="javascript">
<!--
function InputValue(values){
document.form1.input1.value=values;
Layer1.style.display="none";
}
function ShowLayer(){
if(Layer1.style.display==""){
Layer1.style.display="none";
}else{
Layer1.style.display="";
}
}
//-->
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="" style="margin:0">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<input name="input1" type="text" class="inputText" onclick="ShowLayer()">
</td>
</tr>
<tr>
<td>
<div id="Layer1" style="display:none">
<table width="182" border="0" cellpadding="0" cellspacing="0" class="table">
<tr onmouseover="this.className='SelBg'" onmouseout="this.className=''">
<td height="14" onclick="InputValue('地区一')"><div id="Layer2" title="地区一">地区一</div></td>
</tr>
<tr onmouseover="this.className='SelBg'" onmouseout="this.className=''">
<td height="14" onclick="InputValue('地区二')"><div id="Layer2" title="地区二">地区二</div></td>
</tr>
<tr onmouseover="this.className='SelBg'" onmouseout="this.className=''">
<td height="14" onclick="InputValue('地区三')"><div id="Layer2" title="地区三">地区三</div></td>
</tr>
<tr onmouseover="this.className='SelBg'" onmouseout="this.className=''">
<td height="14" onclick="InputValue('地区四')"><div id="Layer2" title="地区四">地区四</div></td>
</tr>
<tr onmouseover="this.className='SelBg'" onmouseout="this.className=''">
<td height="14" onclick="InputValue('地区五')"><div id="Layer2" title="地区五">地区五</div></td>
</tr>
<tr onmouseover="this.className='SelBg'" onmouseout="this.className=''">
<td height="14" onclick="InputValue('地区六')"><div id="Layer2" title="地区六">地区六</div></td>
</tr>
<tr onmouseover="this.className='SelBg'" onmouseout="this.className=''">
<td height="14" onclick="InputValue('地区七')"><div id="Layer2" title="地区七">地区七</div></td>
</tr>
<tr onmouseover="this.className='SelBg'" onmouseout="this.className=''">
<td height="14" onclick="InputValue('地区八')"><div id="Layer2" title="地区八">地区八</div></td>
</tr>
<tr onmouseover="this.className='SelBg'" onmouseout="this.className=''">
<td height="14" onclick="InputValue('地区九')"><div id="Layer2" title="地区九">地区九</div></td>
</tr>
<tr onmouseover="this.className='SelBg'" onmouseout="this.className=''">
<td height="14" onclick="InputValue('地区十')"><div id="Layer2" title="地区十">地区十</div></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
[此贴子已经被作者于2006-4-30 10:13:03编辑过]
我想了想去,其实用不着这么复杂。
[CODE]<script language="JavaScript">
<!-- Hide
function test1() {
document.form1.text1.value=document.form1.select.value
}
// -->
</script>
<form id="form1" name="form1" method="post" action="">
<select name="select" onchange="test1()">
<option selected="selected">请选择</option>
<option value="111">111</option>
<option value="222">222</option>
<option value="">其他</option>
</select>
<input type="text" name="text1">
</form>[/CODE]
把列框中选定的值直接传递到后面的文本框中,如果不在列表框中,就自己输入。