js 怎么获取 select 下拉框选中的值
用js 怎么获取 动态添加行的 select 当前选中的文本框里的值高手帮我看下:代码如下(请复制到自己电脑上运行)
现在的代码只可以获取第一个默认的值,选择其他的,不行。
<html>
<head>
<title> New Document </title>
<script type="text/javascript">
var tab;
var index;
function TableFunction()
{
tab = document.getElementById("tabMain");
var newRow = tab.insertRow(tab.rows.length);
newRow.setAttribute('onmouseout','RowOnMouseout(this)');
newRow.setAttribute('onmousemove','RowOnMouseover(this)');
newRow.setAttribute('style','text-align:center;');
var cell1=newRow.insertCell(-1);
cell1.setAttribute('style','text-align:center;');
newRow.insertCell(-1).innerHTML = '<input onchange="GetHeadgearById(this)" style="width: 100px;border:0px;height:18px;text-align:center;" type="text" value="" />';//首饰编号
newRow.insertCell(-1).innerHTML = '<input onchange="SelectGoods(this)" style="width: 150px;border:0px;height:18px;text-align:center;" type="text" value="" />' //首饰名称
newRow.insertCell(-1).innerHTML='<input type="hidden" id="hntype" />' ;//类型
newRow.insertCell(-1).innerHTML='<input onchange="Sum(this)" style="width: 50px;border:0px;height:18px;text-align:center;" type="text" value="0" />'; //数量
newRow.insertCell(-1).innerHTML='<input style="width: 100px;border:0px;height:18px;text-align:center;" ondblclick="showSales(this)" type="text" /><input type="hidden" id="yyyid" />'; //营业员
newRow.insertCell(-1).innerHTML='<input style="width: 100px;border:0px;height:18px;text-align:center;" type="text" value="0" />'; //积分
newRow.insertCell(-1).innerHTML='<select style="width: 60px;" name="cl_guitai" ><option> 默认</option><option>张三</option> <option>李四</option> </select>';
//newRow.insertCell(-1).innerHTML='<input style="width: 100px;border:0px;height:18px;text-align:center;" ondblclick="showCounter(this)" type="text" />'; //柜台
newRow.insertCell(-1).innerHTML='<select id="celType" style="width: 50px;" onchange="Sum(this)"> <option> </option><option value="Q">数量</option> <option value="W">重量</option></select>'; //公费计价
newRow.insertCell(-1).innerHTML='<input type="text" style="width: 100px;border:0px;height:18px;text-align:center;" value=" " />'; //摘要
//newRow.insertCell(-1).innerHTML= '<input type="hidden" value="" />'; //单位id
CreateLine();
}
function del()
{
tab = document.getElementById("tabMain");
if(tab.rows.length>1)
{
if(confirm("是否真的删除一行!"))
{
tab.deleteRow(tab.rows.length-1);
CreateLine();
}
}
}
//创建连续的行号
function CreateLine()
{
tab =document.getElementById("tabMain");
for(var i=1;i<tab.rows.length;i++)
{
tab.rows[i].cells[0].innerHTML = i;
if(i % 2==0)
{
//tab.rows[i].style.backgroundColor="#DBDAD9";
}
}
}
//获取 select 下拉列表框 选中的值
function test()
{
var tab=document.getElementById("tabMain");
var text="";
for(var i=1;i<tab.rows.length;i++)
{
text =tab.rows[i].cells[7].childNodes[0].options[0].text; // c_counter , 柜台名称
alert(text);
}
}
</script>
</head>
<body >
<input type="button" onclick="TableFunction()" value="加一行" /> <input type="button" onclick="del()" value="减一行" />
<table id="tabMain" style="margin-left:5px;margin-top:5px;" width="800px" border="1" cellpadding="0" cellspacing="0">
<tr style="text-align:center;">
<td>(行号)</td>
<td>首饰编号</td>
<td>首饰名称</td>
<td>类型</td>
<td>数量</td>
<td>营业员</td>
<td>积分</td>
<td>柜台</td>
<td>工费计价</td>
<td>摘要</td>
</tr>
</table>
<input id="Button1" onclick="test()" type="button" value=" 获取柜台选中的值 " />
</body>
</html>
怎么获取呢?
追问:辛苦啦,我这里 是动态 添加的没有 id