标准化工地js动态计算table某列值的总和
/**
*
* @tableId 表格id
* @numId 显⽰张数id
* @index 列数
* @first ⾸次标识
* @obj checkbox对象
*/
function countNum(tableId, numId, index, first,obj) {
var sumStr = ElementById(numId);
/
/当前⾏进⾏加减
if (null != obj) {
var num = new Number(obj.lls[index].innerText);
if (obj.checked) {
sumStr.value = new Number(sumStr.value) + num;
}
el {
sumStr.value = new Number(sumStr.value) - num;
}
}
//遍历所有进⾏加减
el {
var table = ElementById(tableId);
var sum = 0;
var rows = ws;
for (i = 1; i < rows.length; i++) {
//判断是否有复选框
var checkObj = rows[i].cells[0].all[0];
var flag = fal;
if (null != checkObj
&& pe != 'undefined'
&& pe == 'checkbox') {
flag = checkObj.checked;
}
//⾸次默认计算全部或增加选中的值
if (first || flag) {
var num = new Number(rows[i].cells[index].innerText);
sum = sum + num;
}
}
sumStr.value = sum;
}
}
1. jsp,带复选框
龙年快乐<xmdc:form id="AEDT_account">
<xmdc:panelGrid columns="10" width="98%" styleClass="content_table"
align="center" columnwidths="4%,6%,4%,8.5%,4%,6%,5%,5.5%,2.5%,4.5%"
columnaligns="right,left,right,left,right,left,right,left,right,left"
columnClass="content_index,content_body,content_index,content_body,
content_index,content_body,content_index,content_body,content_index,content_body">
<xmdc:outputText value="移交⼈员"></xmdc:outputText>
<xmdc:panelGroup>
<xmdc:inputText
qq端口value="#{ansferOperatorName}"
οnchange="reExport();"></xmdc:inputText>
<xmdc:outputText value="*" ></xmdc:outputText>
</xmdc:panelGroup>
<xmdc:outputText value="移交⽇期"></xmdc:outputText>
<xmdc:panelGroup>
<xmdc:ccbcalendar
value="#{ansferDate}"
id="transferDate"></xmdc:ccbcalendar>
<xmdc:outputText value="*" ></xmdc:outputText>
</xmdc:panelGroup>
<xmdc:outputText value="签收⼈员"></xmdc:outputText>
<xmdc:panelGroup>
<xmdc:inputText
value="#{iveOperatorName}"
οnchange="reExport();"></xmdc:inputText>
<xmdc:outputText value="*" ></xmdc:outputText>
</xmdc:panelGroup>
<xmdc:outputText value="签收⼈员编号"></xmdc:outputText>
<xmdc:panelGroup>
<xmdc:inputText
value="#{iveOperatorNo}"
οnchange="reExport();"></xmdc:inputText>
<xmdc:outputText value="*" ></xmdc:outputText>
</xmdc:panelGroup>
<xmdc:outputText value="张数"></xmdc:outputText>
<xmdc:inputText id="number" readonly="true" ></xmdc:inputText> </xmdc:panelGrid>
<xmdc:panelGrid width="100%">
<xmdc:div styleClass="auto" >
<xmdc:dataTable var="row" cellpadding="2" styleClass="sortable"
value="#{AddExistDataTransfer.unTransferExistList}"
id="countNumT">
<xmdc:column width="4%">
<xmdc:facet name="header">
<xmdc:lectBooleanCheckbox
οnclick="lectAll(this);
countNum('AEDT_account:countNumT', 'AEDT_account:number',4,fal);">
秋天作文开头</xmdc:lectBooleanCheckbox>
</xmdc:facet>
<xmdc:lectBooleanCheckbox value="#{row.lect}"
οnclick="reExport();
countNum('AEDT_account:countNumT', 'AEDT_account:number',4,fal,this);"> </xmdc:lectBooleanCheckbox>
</xmdc:column>
<xmdc:column width="160px">
<xmdc:facet name="header">
<xmdc:outputText value="账号"></xmdc:outputText>
</xmdc:facet>
<xmdc:outputText value="#{row.accountNo}"></xmdc:outputText>
</xmdc:column>
<xmdc:column>
<xmdc:facet name="header">
<xmdc:outputText value="户名"></xmdc:outputText>
</xmdc:facet>
<xmdc:outputText value="#{row.accountName}"></xmdc:outputText>
</xmdc:column>
<xmdc:column>
<xmdc:facet name="header">
<xmdc:outputText value="操作类型"></xmdc:outputText>
</xmdc:facet>
<xmdc:outputText value="#{row.operateType}"></xmdc:outputText>
</xmdc:column>
<xmdc:column>
<xmdc:facet name="header">
<xmdc:outputText value="张数"></xmdc:outputText>
</xmdc:facet>
<xmdc:outputText value="#{unt}"></xmdc:outputText>
</xmdc:column>
</xmdc:dataTable>
</xmdc:div>
快乐玩游戏
</xmdc:panelGrid>描写山水的古诗
<xmdc:verbatim>
<script type="text/javascript">
countNum("AEDT_account:countNumT", "AEDT_account:number",4,true);
</script>
</xmdc:verbatim>
</xmdc:form>
2. jsp,不带复选框
<xmdc:form id="DTRD_account">
<xmdc:panelGrid columns="10" width="98%" styleClass="content_table"
align="center" columnwidths="8%,13%,8%,13%,8%,13%,8%,13%,5%,11%"
columnaligns="right,left,right,left,right,left,right,left,right,left"
columnClass="content_index,content_body,content_index,content_body,
content_index,content_body,content_index,content_body,content_index,content_body"> <xmdc:outputText value="移交⼈"></xmdc:outputText>
<xmdc:outputText
value="#{ansferOperatorName}"></xmdc:outputText> <xmdc:outputText value="移交⽇期"></xmdc:outputText>
<xmdc:outputText
value="#{ansferDate.val}"></xmdc:outputText>
<xmdc:outputText value="签收⼈员"></xmdc:outputText>
<xmdc:outputText
value="#{iveOperatorName}"></xmdc:outputText> <xmdc:outputText value="签收⽇期"></xmdc:outputText>
<xmdc:outputText
value="#{iveDate.val}"></xmdc:outputText>
<xmdc:outputText value="张数"></xmdc:outputText>
<xmdc:inputText id="number" readonly="true"></xmdc:inputText>
</xmdc:panelGrid>
<xmdc:panelGrid width="100%">
<xmdc:div styleClass="auto" >
<xmdc:dataTable var="row" cellpadding="0" styleClass="sortable"
value="#{DataTransferReceiveDetail.detailList}"
id="countNumT">心灵的感悟
<xmdc:column width="165px">
<xmdc:facet name="header">
<xmdc:outputText value="账号"></xmdc:outputText>
</xmdc:facet>
<xmdc:outputText value="#{row.accountNo}"></xmdc:outputText>
</xmdc:column>
<xmdc:column>
<xmdc:facet name="header">
<xmdc:outputText value="户名"></xmdc:outputText>
</xmdc:facet>
<xmdc:outputText value="#{row.accountName}"></xmdc:outputText>
</xmdc:column>
一粒红尘电视剧<xmdc:column>
<xmdc:facet name="header">
<xmdc:outputText value="操作类型"></xmdc:outputText>
</xmdc:facet>
<xmdc:outputText value="#{row.operateType}"></xmdc:outputText>
</xmdc:column>
<xmdc:column>
<xmdc:facet name="header">
<xmdc:outputText value="张数"></xmdc:outputText>
</xmdc:facet>
<xmdc:outputText value="#{unt}"></xmdc:outputText>
</xmdc:column>
<xmdc:column>
<xmdc:facet name="header">
<xmdc:outputText value="是否电⼦审批"></xmdc:outputText>
</xmdc:facet>
<xmdc:outputText value="#{hief}"></xmdc:outputText>
</xmdc:column>
</xmdc:dataTable>
</xmdc:div>
</xmdc:panelGrid>
<xmdc:verbatim>
<script type="text/javascript">
countNum("DTRD_account:countNumT", "DTRD_account:number",3,true); </script>
</xmdc:verbatim>
</xmdc:form>