页面有如下table:
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" class="contentTable">
<tr>
<td height="28" width="25%" class="fieldName" align="center">元素排列顺序</td>
<td height="28" width="25%" class="fieldName" align="center">元素项</td>
<td height="28" width="25%" class="fieldName" align="center">元素值</td>
<td height="28" width="25%" class="fieldName" align="center">元素长度</td>
</tr>
<c:forEach var="voucherFlowRule" items="${voucherFlowRule}">
<tr>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementOrder}</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementDesc}</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementValue}</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementLength}</td>
</tr>
</c:forEach>
</table>
<input type="button" name="viewFlow" value="预览合并后的元素值" class="btn" onClick="reviewFlowNum()"/>
<input tye="text" id="element" class="fieldContent"/>
请问怎么将table中所有的元素值合并并输出到element中,按钮实现的javascript函数reviewFlowNum怎么写?
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" class="contentTable">
<tr>
<td height="28" width="25%" class="fieldName" align="center">元素排列顺序</td>
<td height="28" width="25%" class="fieldName" align="center">元素项</td>
<td height="28" width="25%" class="fieldName" align="center">元素值</td>
<td height="28" width="25%" class="fieldName" align="center">元素长度</td>
</tr>
<c:forEach var="voucherFlowRule" items="${voucherFlowRule}">
<tr>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementOrder}</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementDesc}</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementValue}</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementLength}</td>
</tr>
</c:forEach>
</table>
<input type="button" name="viewFlow" value="预览合并后的元素值" class="btn" onClick="reviewFlowNum()"/>
<input tye="text" id="element" class="fieldContent"/>
请问怎么将table中所有的元素值合并并输出到element中,按钮实现的javascript函数reviewFlowNum怎么写?
解决方案 »
- 如何让一个标题显示在java-applet小程序上 html zindex 套层
- js拖动div并保存位置
- 调用vc写的Activex控件函数时带句柄,这个句柄怎么传递?
- 动态下拉框的实现
- 大难题来了! 有什么办法通过JavaScript实现实时的语法高亮显示?
- 高手请进,菜鸟碰到项目难题了:求根据XML生成动态的表格,表格的列是动态且嵌套,分不够再加的
- 新手疑问
- kendo ui 能否实现frozen Column?
- 如何在网页中实现类似EXCLE的表格?
- 求助:如何判断一个ActiveXObject对象是否创建?
- web版游戏怎么实现联机对战啊?
- setCapture(), addEventListener()问题
合并输出到input中
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
function reviewFlowNum(){
var i ='';
$("table tr:gt(0) td:nth-child(3)").each(function(){
i += $(this).text();
});
$("#element").val(i);
}
</script>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" class="contentTable">
<tr>
<td height="28" width="25%" class="fieldName" align="center">元素排列顺序</td>
<td height="28" width="25%" class="fieldName" align="center">元素项</td>
<td height="28" width="25%" class="fieldName" align="center">元素值</td>
<td height="28" width="25%" class="fieldName" align="center">元素长度</td>
</tr>
<tr>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementOrder}</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementDesc}</td>
<td height="28" width="25%" align="center" class="fieldContent">1</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementLength}</td>
</tr>
<tr>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementOrder}</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementDesc}</td>
<td height="28" width="25%" align="center" class="fieldContent">2</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementLength}</td>
</tr>
<tr>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementOrder}</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementDesc}</td>
<td height="28" width="25%" align="center" class="fieldContent">3</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementLength}</td>
</tr>
<tr>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementOrder}</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementDesc}</td>
<td height="28" width="25%" align="center" class="fieldContent">4</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementLength}</td>
</tr>
<tr>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementOrder}</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementDesc}</td>
<td height="28" width="25%" align="center" class="fieldContent">5</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementLength}</td>
</tr>
<tr>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementOrder}</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementDesc}</td>
<td height="28" width="25%" align="center" class="fieldContent">6</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementLength}</td>
</tr>
<tr>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementOrder}</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementDesc}</td>
<td height="28" width="25%" align="center" class="fieldContent">7</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementLength}</td>
</tr>
<tr>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementOrder}</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementDesc}</td>
<td height="28" width="25%" align="center" class="fieldContent">8</td>
<td height="28" width="25%" align="center" class="fieldContent">${voucherFlowRule.elementLength}</td>
</tr>
</tr>
</table>
<input type="button" name="viewFlow" value="预览合并后的元素值" class="btn" onClick="reviewFlowNum()"/>
<input type="text" id="element" class="fieldContent"/>
</body>
</html>
var r =[];
$("table tr:gt(0) td:nth-child(3)").each(function(){
r.push( $(this).text());
});
$("#element").val(r.join('')); // r.join(',')
}用数组 push join 性能是远远高于字符串拼接的
table => #id
如果有class且唯一 .class
如果有name
table[name='你的name']