是的,这是我从网上找来的:<HTML>
<HEAD>
<META http-equiv='Content-Type' content='text/html; charset=gb2312'>
<TITLE>可输入的下拉框</TITLE>
</HEAD>
<BODY ><div style="position:relative;">
<span style="margin-left:100px;width:18px;overflow:hidden;">
<select style="width:118px;margin-left:-100px" onchange="this.parentNode.nextSibling.value=this.value">
<option value="YOU"> 你 </option>
<option value="MY"> 我 </option>
<option value="HE"> 他 </option>
</select></span><input name="box" style="width:100px;position:absolute;left:0px;">
</div>
</BODY></HTML>这是静态的,但我需要可动态增加的,请教!
<HEAD>
<META http-equiv='Content-Type' content='text/html; charset=gb2312'>
<TITLE>可输入的下拉框</TITLE>
</HEAD>
<BODY ><div style="position:relative;">
<span style="margin-left:100px;width:18px;overflow:hidden;">
<select style="width:118px;margin-left:-100px" onchange="this.parentNode.nextSibling.value=this.value">
<option value="YOU"> 你 </option>
<option value="MY"> 我 </option>
<option value="HE"> 他 </option>
</select></span><input name="box" style="width:100px;position:absolute;left:0px;">
</div>
</BODY></HTML>这是静态的,但我需要可动态增加的,请教!
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Test</title>
</head><body>
<script> var textNumber = 1;function change()
{
/*两个都不行*/
document.all.box.value = document.all.select1.value;
document.all.input1.value = document.all.oSelect.value;
}function DeleteTr(i)
{
var table = document.getElementById("table1");
var tr = table.childNodes[0]; tr.removeChild(tr.childNodes[i]);
} function AppendTr()
{
textNumber++;var table = document.getElementById("table1");
var tr = table.childNodes[0]; var trnew = document.createElement("tr");var td1 = document.createElement("td");var oSelect = document.createElement("select");
oSelect.setAttribute("id","select1");
oSelect.setAttribute("onChange","change()");
var option11 = document.createElement("option");
option11.text="A.你";
option11.value="YOU";
oSelect.add(option11);
var option12 = document.createElement("option");
option12.text="B.我";
option12.value="MY";
oSelect.add(option12);
var option13 = document.createElement("option");
option13.text="C.他";
option13.value="HE";
oSelect.add(option13);var td2 = document.createElement("td");
var input1 = document.createElement("input");
input1.setAttribute("name","box");
input1.setAttribute("id","box" );
td1.appendChild(oSelect);
td2.appendChild(input1); trnew.appendChild(td1);
trnew.appendChild(td2); tr.appendChild(trnew);
} </script> <table border="0" cellspacing="0" bgcolor="#CCCCCC" id="table1">
</table> <input type="button" onclick="DeleteTr(0);" value="删除一行">
<input type="button" onclick="AppendTr();" value="插入一行">
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Test</title>
</head><body>
<script> var textNumber = 1;function change()
{
/*两个都不行*/
//document.all.box.value = document.all.select1.value;
//document.all.input1.value = document.all.oSelect.value;
alert("123")
document.getElementById("box").value=document.getElementById("selec").value
}function DeleteTr(i)
{
var table = document.getElementById("table1");
var tr = table.childNodes[0]; tr.removeChild(tr.childNodes[i]);
} function AppendTr()
{
textNumber++;var table = document.getElementById("table1");
var tr = table.childNodes[0]; var trnew = document.createElement("tr");var td1 = document.createElement("td");var oSelect = document.createElement("select");
oSelect.setAttribute("id","select1");
oSelect.setAttribute("onChange","change()");
var option11 = document.createElement("option");
option11.text="A.你";
option11.value="YOU";
oSelect.add(option11);
var option12 = document.createElement("option");
option12.text="B.我";
option12.value="MY";
oSelect.add(option12);
var option13 = document.createElement("option");
option13.text="C.他";
option13.value="HE";
oSelect.add(option13);var td2 = document.createElement("td");
var input1 = document.createElement("input");
input1.setAttribute("name","box");
input1.setAttribute("id","box" );
//td1.appendChild(oSelect);
td1.innerHTML="<select onchange='change()' id='selec'><option value='YOU'> 你 </option><option value='YOU1'> 你1 </option></select>"
td2.appendChild(input1); trnew.appendChild(td1);
trnew.appendChild(td2); tr.appendChild(trnew);
} </script> <table border="0" cellspacing="0" bgcolor="#CCCCCC" id="table1">
</table> <input type="button" onclick="DeleteTr(0);" value="删除一行">
<input type="button" onclick="AppendTr();" value="插入一行">
</body>
</html>
function change()
{
/*两个都不行*/
//document.all.box.value = document.all.select1.value;
//document.all.input1.value = document.all.oSelect.value;
alert("123")
document.getElementById("box").value=document.getElementById("selec").value
}
里面要写别的才行 不染会出错你的问题主要是 你那样添加的onchange 事件触发不了,事件不是那样添加的
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Test</title>
</head><body>
<script> var textNumber = 1;function change(a)
{
/*两个都不行*/
//document.all.box.value = document.all.select1.value;
//document.all.input1.value = document.all.oSelect.value;
alert("123")
//alert(a.value)
//document.getElementById("box").value=document.getElementById("selec").value
//alert(a.parentNode.parentNode.innerHTML)
//a.parentNode.parentNode.parentNode.childNodes[1].childNodes[0].value=a.value
//alert(a.parentNode.parentNode.childNodes[1].value=a.value)
a.parentNode.nextSibling.childNodes[0].value=a.value
}function DeleteTr(i)
{
var table = document.getElementById("table1");
var tr = table.childNodes[0]; tr.removeChild(tr.childNodes[i]);
} function AppendTr()
{
textNumber++;var table = document.getElementById("table1");
var tr = table.childNodes[0]; var trnew = document.createElement("tr");var td1 = document.createElement("td");var oSelect = document.createElement("select");
oSelect.setAttribute("id","select1");
oSelect.setAttribute("onChange","change()");
var option11 = document.createElement("option");
option11.text="A.你";
option11.value="YOU";
oSelect.add(option11);
var option12 = document.createElement("option");
option12.text="B.我";
option12.value="MY";
oSelect.add(option12);
var option13 = document.createElement("option");
option13.text="C.他";
option13.value="HE";
oSelect.add(option13);var td2 = document.createElement("td");
var input1 = document.createElement("input");
input1.setAttribute("name","box");
input1.setAttribute("id","box" );
//td1.appendChild(oSelect);
td1.innerHTML="<select onchange='change(this)' id='selec'><option value='YOU'> 你 </option><option value='YOU1'> 你1 </option></select>"
td2.appendChild(input1); trnew.appendChild(td1);
trnew.appendChild(td2); tr.appendChild(trnew);
} </script> <table border="0" cellspacing="0" bgcolor="#CCCCCC" id="table1">
</table> <input type="button" onclick="DeleteTr(0);" value="删除一行">
<input type="button" onclick="AppendTr();" value="插入一行">
</body>
</html>
{a.parentNode.nextSibling.childNodes[0].value=a.options[a.selectedIndex].value
}也可以
不要 change 也可,如上改