一下的程序都是在引用util.js文件的情况下运行的
处理列表:处理列表--字符串数组
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>处理列表--字符串数组</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="js/util.js"></script>
<script type="text/javascript">
var strArray = ['请选择一本书','Java','Hibernate','Spring',];
function add(){
dwr.util.addOptions("test",strArray);
}
function del(){
dwr.util.removeAllOptions("test");
}
</script>
</head>
<body>
<select id="test"></select>
<input type="button" value="添加选项" onclick="add();">
<input type="button" value="删除选项" onclick="del();">
</body>
</html>
处理列表--对象数组
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>处理列表--对象数组</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="js/util.js"></script>
<script type="text/javascript">
var objArray = [{name:'Java'},
{name:'Hibernate'},
{name:'Spring'}];
function add(){
dwr.util.addOptions("test",objArray,"name");
}
function del(){
dwr.util.removeAllOptions("test");
}
</script>
</head>
<body>
<select id="test"></select>
<input type="button" value="添加选项" onclick="add();">
<input type="button" value="删除选项" onclick="del();">
</body>
</html>
处理列表--使用对象作为属性值的对象
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>处理列表--使用对象作为属性值的对象</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="js/util.js"></script>
<script type="text/javascript">
//定义一个每个属性值都是对象的对象
var objMap = {
first:{book:'Java',price:'55'},
second:{book:'Hibernate',price:'66'},
third:{book:'Spring',price:'77'},
fourth:{book:'Struts2',price:'88'}
};
function add(){
//对象数组为列表框添加列表项
//以第三个参数指定的属性作为各列表项的值(value)
//以第四个参数指定的属性作为各列表项的文本
dwr.util.addOptions("test",objMap,"price","book");
}
function del(){
//删除所有的列表项
dwr.util.removeAllOptions("test");
}
</script>
</head>
<body>
<select id="test"></select>
<input type="button" value="添加选项" onclick="add();">
<input type="button" value="删除选项" onclick="del();">
</body>
</html>
处理列表--对象
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>处理列表--对象</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="js/util.js"></script>
<script type="text/javascript">
//定义一个JavaScript对象
var book = {
name:"Java",
price:"55",
publish:"长沙"
}
function add(){
dwr.util.addOptions("test",book);
}
function del(){
dwr.util.removeAllOptions("test");
}
</script>
</head>
<body>
<select id="test"></select>
<input type="button" value="添加选项" onclick="add();">
<input type="button" value="删除选项" onclick="del();">
</body>
</html>
util.js测试
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>util.js测试</title>
<meta name="website" content="http://www.crazyit.org" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="js/util.js" type="text/javascript"></script>
</head>
<body>
<ol id="test"></ol>
<input type="button" value="添加选项" onclick="add();"/>
<input type="button" value="删除选项" onclick="del();"/>
<script type="text/javascript">
//定义一个对象数组
var objArr = [ {
name : 'Java'
}, {
name : 'Ajax'
}, {
name : 'XML'
} ];
function add() {
//以对象数组为列表框添加列表项
dwr.util.addOptions("test", objArr, 'name');
}
function del() {
//删除所有列表项
dwr.util.removeAllOptions("test");
}
</script>
</body>
</html>
util.js测试二
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>util.js测试</title>
<meta name="website" content="http://www.crazyit.org" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="js/util.js" type="text/javascript"></script>
</head>
<body>
<ol id="test"></ol>
<input type="button" value="添加选项" onclick="add();"/>
<input type="button" value="删除选项" onclick="del();"/>
<script type="text/javascript">
//定义一个对象数组
var objArr = [ {
book : 'Java',price:'55'
}, {
book : 'Ajax',price:'66'
}, {
book : 'XML',price:'77'
} ];
function add() {
//以对象数组为列表框添加列表项
//以第三个参数指定的属性作为各列表的文本
//第四个参数已经没用用了
dwr.util.addOptions("test", objArr, 'book','price');
}
function del() {
//删除所有列表项
dwr.util.removeAllOptions("test");
}
</script>
</body>
</html>