在JSF的标签环境下统计table里Input里的值

<%@ page session="false" contentType="text/html;charset=utf-8"%>

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>


<f:view>


<HTML>

<HEAD>

<script language="javascript" type="text/Javascript">

function a() {

var table = document.all['aa:bb'];

var length = table.rows.length;

var sum = 0;

for ( var i = 0; i < length - 1; i++) {

var inputvalue = document.all['aa:bb:' + i + ':cc'];

 

if (inputvalue.value == '') {

continue;

} else {

sum=parseFloat(sum)+parseFloat(inputvalue.value);

}

}

var edcba=document.getElementById("abcde");

edcba.value=sum;

}

</script>




</HEAD>

<BODY>

<CENTER><h:form id="aa">


   name<h:inputText value="#{person.name}"></h:inputText>

  id<h:inputText value="#{person.id}"></h:inputText>

<br>

<h:commandButton value="search" action="#{person.findUsersList}"></h:commandButton>


<h:inputText title="aa" onchange="a();" />

 每页显示的结果数:<h:selectOneMenu value="#{person.account}" immediate="true"

onchange="this.form.submit();">

<f:selectItems value="#{person.showItems}" />

</h:selectOneMenu>

<h:commandButton value="AddItem" action="#{person.addItem}"></h:commandButton>




<h:dataTable value="#{person.showUsers}" var="user" border="1" id="bb">

<h:column>

<f:facet name="header">

<h:outputText value="NO" />

</f:facet>

<h:commandLink action="#{person.select}">

<h:outputText value="#{person.rowIndex}" />

</h:commandLink>

</h:column>


<h:column>

<f:facet name="header">

<h:outputText value="NAME" />

</f:facet>

<h:outputText value="#{user.name}" />


</h:column>


<h:column>

<f:facet name="header">

<h:outputText value="ID" />

</f:facet>

<h:outputText value="#{user.id}" />

</h:column>


<h:column>

<f:facet name="header">

<h:outputText value="floatValue" />

</f:facet>

<h:inputText id="cc" onchange="a();" />

</h:column>

</h:dataTable>

<input id="abcde" />

</h:form></CENTER>

</BODY>

</HTML>

</f:view>


普通html里统计input里的值:

<html>

<head>

<title>javascript计算text中的值</title>

<style>

 </style>

<script type="text/javascript">

function calculate() {

var x=document.getElementsByTagName("input");

 var sum=0;

for(var i=0;i<x.length;i++){

    sum+=parseFloat(x[i].value)

 }

 alert(sum);

 }

 </script>

</head>

<body>

<input type="text"  />

<input type="text"  />

<br/>

<button type="button"  onclick="calculate();">统计</button>

</body>

</html> 

阅读更多
个人分类: JavaScript
上一篇职场英语--二十三 询问
下一篇职场英语--二十四 开展对话
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭