DWRUtil.getText(id)
可以根据id取得text的值,这个方法只能用于select list
DWRUtil.getValue(id)
可以根据id取得value,使用这个方法,你不必在意div和select list的不同。
DWRUtil.getValues()
getValues() is similar to getValue() except that the input is a Javascript object that contains name/value pairs. The names are assumed to be the IDs of HTML elements, and the values are altered to reflect the contents of those IDs. This method does not return the object in question, it alters the value that you pass to it.这个方法和getValue()一样,只是它传入的是一个包含名字和数值的javascript对象.这个名字就是HTML元素的ID。这个方法不会返回任何对象,它只会将ID的value映射给传入的value。例:
function doGetValues() {
var text= "{
div:null,
textarea:null,
select:null,
text:null,
password:null,
formbutton:null,
button:null
}";
var object = objectEval(text); //javascript对象
DWRUtil.getValues(object);
var reply = DWRUtil.toDescriptiveString(object, 2); //toString
reply = reply.replace(/\n/g, "<br/>"); //转意
DWRUtil.setValue("getvaluesret", reply); //显示
}
DWRUtil.setValue(id, value)
用ID找到元素,并更新value
DWRUtil.setValues()
和setValue(id,value)一样,只是它需要的参数是个javascript对象,如:
DWRUtil.setValues({
div: "new div content",
password: "1234567890"
});
DWRUtil.toDescriptiveString
带debug信息的toString,第一个为将要debug的对象,第二个参数为处理等级。等级如下:
· 0: Single line of debug 单行调试
· 1: Multi-line debug that does not dig into child objects 不分析子元素的多行调试
· 2: Multi-line debug that digs into the 2nd layer of child objects 最多分析到第二层子元素的多行调试
· And so on. Level 2 and greater probably produce too much output.
总结:DWR不但屏蔽了许多client与server交互的重复且复杂的代码,而且还提供了一些常用的方法,一些思想还是从prototype继承而来,并有一定的改进。同时,它也考虑到了与struts、hibernate、spring的结合问题。
需要注意的是,DWR是一种把服务器端的java代码通过javascript直接从浏览器调用的方法(DWR isa way of calling Java code on the server directly from Javascript in the browser.),而不是一个javascript的库(Generally speaking DWR is not a generic JavaScript library so it does not attempt to provide fill this need. However this is one of these really useful functions to have around if you are doing Ajax work.)能做到怎么多,已经很难得了。
DWR自04年11月草案提出到现在的Version 1.1 beta 3(2005-12-29),已经更新发布了20多次了,但愿在ajax的发展大路上,能始终看见DWR的身影。