选择下拉框的值 显示在同一页面的表格中 怎么实现? 一排下拉框 选择之后 点击添加 所选择的值被添加到页面中的表格。js怎么实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><body> <select id="sel"> <option value="1">1</option> <option value="2">2</option> </select> <table id="tab"> <tr> <td>1</td> </tr> </table> <input type="button" value="添加" id="btn" /> <script> document.getElementById('btn').onclick = function(){ var value = document.getElementById('sel')[document.getElementById('sel').selectedIndex].value; var tr = document.createElement('tr'); var td = document.createElement('td'); td.innerHTML = value; tr.appendChild(td); document.getElementById('tab').appendChild(tr); }; </script></body></html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><body> <select id="sel"> <option value="1">1</option> <option value="2">2</option> </select> <table id="tab"> <tr> <td>1</td> </tr> </table> <input type="button" value="添加" id="btn" /> <input type="button" value="删除" id="del" /> <script> document.getElementById('btn').onclick = function(){ var value = document.getElementById('sel')[document.getElementById('sel').selectedIndex].value; var tr = document.createElement('tr'); var td = document.createElement('td'); td.innerHTML = value; tr.appendChild(td); document.getElementById('tab').appendChild(tr); }; document.getElementById('del').onclick = function(){ if(document.getElementById('tab').getElementsByTagName('tr').length - 1 > 0){ document.getElementById('tab').removeChild(document.getElementById('tab').getElementsByTagName('tr')[document.getElementById('tab').getElementsByTagName('tr').length - 1]); }else{ } }; </script></body></html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><body> <select id="sel"> <option value="1">1</option> <option value="2">2</option> </select> <table id="tab"> <tr> <td>1</td> </tr> </table> <input type="button" value="添加" id="btn" /> <script> document.getElementById('btn').onclick = function(){ var value = document.getElementById('sel')[document.getElementById('sel').selectedIndex].value; var tr = document.createElement('tr'); var td = document.createElement('td'); td.innerHTML = value; tr.appendChild(td); document.getElementById('tab').appendChild(tr); var input = document.createElement("input"); input.type ='button'; input.value = '删除'; td.appendChild(input); input.onclick = function(){ document.getElementById('tab').removeChild(input.parentNode.parentNode); } }; </script></body></html>借用1楼。 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><body> <select id="sel"> <option value="1">1</option> <option value="2">2</option> </select> <select id="sel2"> <option value="3">3</option> <option value="4">4</option> </select> <table id="tab"> <tr> <td>1</td> </tr> </table> <input type="button" value="添加" id="btn" /> <input type="button" value="删除" id="del" /> <script> document.getElementById('btn').onclick = function(){ var value = document.getElementById('sel')[document.getElementById('sel').selectedIndex].value; var value2 = document.getElementById('sel2')[document.getElementById('sel2').selectedIndex].value; var tr = document.createElement('tr'); var td1 = document.createElement('td'); var td2 = document.createElement('td'); td1.innerHTML = value; td2.innerHTML = value2; tr.appendChild(td1); tr.appendChild(td2); document.getElementById('tab').appendChild(tr); }; document.getElementById('del').onclick = function(){ if(document.getElementById('tab').getElementsByTagName('tr').length - 1 > 0){ document.getElementById('tab').removeChild(document.getElementById('tab').getElementsByTagName('tr')[document.getElementById('tab').getElementsByTagName('tr').length - 1]); }else{ } }; </script></body></html> js怎么判断对象存在不 如何设置html:select以及html:text为不可用 web service 掌上应用可以开发那些游戏 js数组问题 转帖,为什么FireFox处理XMl有问题 javascript 想屏蔽键盘方向键控制div1(外层)的滚动条,却导致了div2(里层)里的文本框不能输入文字了,怎么解决 showModalDialog()问题, 在线等~~~! 图片路径的问题 我在网页中插入了一个自己写的控件,如何在javascript中调用这个控件的方法? 在线等待,对于高手的确是个简单的问题!! 关于导航栏的细节问题 急急!!!!!! js解析xml的问题,求教
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<select id="sel">
<option value="1">1</option>
<option value="2">2</option>
</select>
<table id="tab">
<tr>
<td>1</td>
</tr>
</table>
<input type="button" value="添加" id="btn" />
<script>
document.getElementById('btn').onclick = function(){
var value = document.getElementById('sel')[document.getElementById('sel').selectedIndex].value;
var tr = document.createElement('tr');
var td = document.createElement('td');
td.innerHTML = value;
tr.appendChild(td);
document.getElementById('tab').appendChild(tr);
};
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<select id="sel">
<option value="1">1</option>
<option value="2">2</option>
</select>
<table id="tab">
<tr>
<td>1</td>
</tr>
</table>
<input type="button" value="添加" id="btn" />
<input type="button" value="删除" id="del" />
<script>
document.getElementById('btn').onclick = function(){
var value = document.getElementById('sel')[document.getElementById('sel').selectedIndex].value;
var tr = document.createElement('tr');
var td = document.createElement('td');
td.innerHTML = value;
tr.appendChild(td);
document.getElementById('tab').appendChild(tr);
};
document.getElementById('del').onclick = function(){
if(document.getElementById('tab').getElementsByTagName('tr').length - 1 > 0){
document.getElementById('tab').removeChild(document.getElementById('tab').getElementsByTagName('tr')[document.getElementById('tab').getElementsByTagName('tr').length - 1]);
}else{
}
};
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<select id="sel">
<option value="1">1</option>
<option value="2">2</option>
</select>
<table id="tab">
<tr>
<td>1</td>
</tr>
</table>
<input type="button" value="添加" id="btn" />
<script>
document.getElementById('btn').onclick = function(){
var value = document.getElementById('sel')[document.getElementById('sel').selectedIndex].value;
var tr = document.createElement('tr');
var td = document.createElement('td');
td.innerHTML = value;
tr.appendChild(td);
document.getElementById('tab').appendChild(tr);
var input = document.createElement("input");
input.type ='button';
input.value = '删除';
td.appendChild(input);
input.onclick = function(){
document.getElementById('tab').removeChild(input.parentNode.parentNode);
}
};
</script>
</body>
</html>借用1楼。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<select id="sel">
<option value="1">1</option>
<option value="2">2</option>
</select>
<select id="sel2">
<option value="3">3</option>
<option value="4">4</option>
</select>
<table id="tab">
<tr>
<td>1</td>
</tr>
</table>
<input type="button" value="添加" id="btn" />
<input type="button" value="删除" id="del" />
<script>
document.getElementById('btn').onclick = function(){
var value = document.getElementById('sel')[document.getElementById('sel').selectedIndex].value;
var value2 = document.getElementById('sel2')[document.getElementById('sel2').selectedIndex].value;
var tr = document.createElement('tr');
var td1 = document.createElement('td');
var td2 = document.createElement('td');
td1.innerHTML = value;
td2.innerHTML = value2;
tr.appendChild(td1);
tr.appendChild(td2);
document.getElementById('tab').appendChild(tr);
};
document.getElementById('del').onclick = function(){
if(document.getElementById('tab').getElementsByTagName('tr').length - 1 > 0){
document.getElementById('tab').removeChild(document.getElementById('tab').getElementsByTagName('tr')[document.getElementById('tab').getElementsByTagName('tr').length - 1]);
}else{
}
};
</script>
</body>
</html>