问题如题:假如我在action中将必要的值给了list,list中的值有(小明,2010-01-01,0,0121)分别表示(姓名,生日,性别0为男,1表示身份,其中身份的值见map中的值),而map中的内容有(["0121","政府官员"]["0510","农民"])。
以上是action中传来的值。在js中如何将name给table中不同td中(注:每个td中元素有自己的id号,而身份为一个下拉框,下拉框默认值为list中的0121,显示为政府官员)。最好有js代码(jquery更好)。
刚学js,很多不懂,请高手支招吧,非常感谢!
以下为jsp中的部分代码:
<div id="div1">
<table id="table">
<tr>
<td><input type="text" id="user"/></td>
<td><input type="text" id="bir"/></td>
<td><select name="sex" id="sex"></td>
<td><select name="role" id="role"></td>
</tr>
</table>
</div>
以上是action中传来的值。在js中如何将name给table中不同td中(注:每个td中元素有自己的id号,而身份为一个下拉框,下拉框默认值为list中的0121,显示为政府官员)。最好有js代码(jquery更好)。
刚学js,很多不懂,请高手支招吧,非常感谢!
以下为jsp中的部分代码:
<div id="div1">
<table id="table">
<tr>
<td><input type="text" id="user"/></td>
<td><input type="text" id="bir"/></td>
<td><select name="sex" id="sex"></td>
<td><select name="role" id="role"></td>
</tr>
</table>
</div>
既然能从服务器那里得到数据 说明应该是动态网页 动态网页的话应该有专门的语言来实现的啊 比如jsp可以用java小脚本或者el表达式之类的等等 感觉用小脚本加html标签很容易就能实现你要的功能了 js的话比较麻烦 呵呵
pageEncoding="UTF-8" errorPage="error.jsp" import="java.util.*,com.test.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<table>
<th>id</th>
<th>name</th>
<th>date</th>
<th>sex</th>
<th>ident</th>
<%
int i=0;
List<CustomerBean>list=(List<CustomerBean>)session.getAttribute("list");
for(CustomerBean cb:list){
i++;
%>
<tr>
<td><%=i %></td>
<td><%=cb.getName() %></td>
<td><%=cb.getDate() %></td>
<td>
<select sex="<%=cb.getSex()%>">
<option>男</option>
<option>女</option>
</select>
</td>
<td>
<select ident="<%=cb.getIdentity()%>">
<option>政府人员</option>
<option>平民</option>
</select>
</td>
</tr>
<%
}
%>
<table>
<script type="text/javascript">
var a=document.getElementsByTagName("select");
for(var i=0;i<a.length;i++){
if(a[i].sex){
if(a[i].sex=="0"){
a[i][0].selected="selected";
}else{
a[i][1].selected="selected";
}
}else if(a[i].ident){
if(a[i].ident=="0121"){
a[i][0].selected="selected";
}else{
a[i][1].selected="selected";
}
}
}
</script>
</body>
</html>
这样试试
问题好解决。用2个forEach。不要怀疑我这是错的。一定OK的。
<c:forEach var="list" items="${list}">
<c:forEach var="map"
<td>map.name </td>
items="${map[list.id]}">
</c:forEach>
</c:forEach>
问题好解决。用2个forEach。不要怀疑我这是错的。一定OK的。
<c:forEach var="list" items="${list}">
<c:forEach var="map"
<td>map.name </td>
items="${map[list.id]}"></c:forEach>
</c:forEach>
[/Quote]我知道上面的方法,我的意思是要在js获取,并赋值给table中的不同td。
正解!!前台可以在dwr中解析json,遍历json对象,生成表格数据
<javascript>var list = "<s:property value="list" />";
var map = "<s:property value="map" />";
alert(list);
alert(map);
</javascript>