var tab = document.getElementById('tab'); var input = document.createElement('input'); input.type = 'text'; var _select = document.createElement('select'); var option = document.createElement('option'); _select.appendChild(option); var tr = document.createElement('tr'); var td = document.createElement('td'); var td2 = document.createElement('td');
楼主你是想把用户输入的内容加入到select下拉框里是吗?
<select id="sel" style="width:200px;"></select>
<input type="button" id="btn" />
<script>
document.getElementById('btn').onclick = function(){
var value = document.getElementById('text').value;
var option = document.createElement('option');
option.value = value;
option.innerHTML = value;
document.getElementById('sel').appendChild(option);
};
</script>这个意思?
<input type='text' id="zhi" />
<input type='button' value='点击添加文本框的内容进下拉框' onclick='jin()' /><script type="javascript/css">
function jin(){
var va = $("#zhi").val().trim();
var op=$("<option></option>");
op.text(va);
op.appendTo($("#gg"));
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TEST</title></head>
<body>
<input type="button" value="click me" id="btn" />
<table>
<tbody id="tab">
<tr>
<td><input type="text" /></td>
<td><select><option></option></select></td>
</tr>
</tbody>
</table><script type="text/javascript">
document.getElementById('btn').onclick = function(){
var tab = document.getElementById('tab');
var input = document.createElement('input');
input.type = 'text';
var _select = document.createElement('select');
var option = document.createElement('option');
_select.appendChild(option);
var tr = document.createElement('tr');
var td = document.createElement('td');
var td2 = document.createElement('td');
td.appendChild(input);
td2.appendChild(_select);
tr.appendChild(td);
tr.appendChild(td2);
tab.appendChild(tr);
};
</script>
</body>
</html>