这些功能函数在下面这个网址都有示例,这里只是把他们用中文解释,方便查找.
http://getahead.ltd.uk/dwr/browser/util
DWRUtil.getText(id)
这个函数只能用于select
getText(id) is similar to getValue(id), except that it is designed for <select ... lists where you need to get the displayed text rather than the value of the current option.
这个函数主要的作用是取到当前select的显示值即<option value>xxx</option>中xxx的内容
DWRUtil.getValue(id) 用来得到<option value>xxx</option>等元素的value值
DWRUtil.getValue(id) is the read version of setValue(). This gets the values out of the HTML elements without you needing to worry about how a selection list differs from a div.
这个函数能用于多个元素input type =textarea,text,Form button,formbutton,password(明文),
Fancy button等元素,主要可以屏蔽原来对select元素getValue操作带来的不便
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()操作,并将value的结果以js对象的形式封装起来返回,参数是一个js对象,其中包含了希望取到value的element id
e.g
{
div:null,
textarea:null,
select:null,
text:null,
password:null,
formbutton:null,
button:null
}
详细参考http://getahead.ltd.uk/dwr/browser/util/getvalues查看效果
DWRUtil.onReturn
When inputs are part of a form then the return key causes the form to be submitted. When you are using Ajax, this is generally not what you want. Usually it would be far better if some JavaScript was triggered.Unfortunately different browsers handle events in quite a different manner. So DWRUtil.onReturn patches over the differences.
在一个form表单中敲回车键将导致表单被递交,这往往不是我们希望看到的.但是很多浏览器对这个事件的处理是不统一的,这个函数就是为了消除这个不统一的
DWRUtil.onReturn(event, submitFunction)
DWRUtil.selectRange
Selecting a range of text in an input box
You need to select text in an input box for any "Google suggest" type functions, however the selection model changes a lot between different browsers. The DWRUtil function to help here is: DWRUtil.selectRange(ele, start, end).
在一个input元素中选择一个范围的字符串,可以查看
http://getahead.ltd.uk/dwr/browser/util/selectrange操作
DWRUtil.setValue(id, value)
DWRUtil.setValue(id, value) finds the element with the id specified in the first parameter and alters its contents to be the value in the second parameter.
This method works for almost all HTML elements including selects (where the option with a matching value and not text is selected), input elements (including textareas) divs and spans.
主要是为了设值,屏蔽了select元素设值的问题,对select也可以方便的setvalue
DWRUtil.setValues()
Similar to setValue 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, what we should set the contents of the elements.
与getValues对应,传入js对象,将对象中的value传给相应的element
DWRUtil.toDescriptiveString(id,degree)
DWRUtil.toDescriptiveString is a better version of the toString() than the default. This function has a third parameter that declares the initial indent. This function should not be used from the outside world as it may well change in the future.
此函数主要用来调试,传入元素的id,调试的degree将显示DOM信息
此函数有第三个参数,用于声明初始化,包含第三个参数的调用不应该为使用,因为这个函数将来会改变
DWRUtil.useLoadingMessage
You must call this method after the page has loaded (i.e. not before the onload() event has fired) because it creates a hidden div to contain the loading message.
你必须在页面加载完成后(body onload事件)调用这个函数,因为它会创建一个div,来包含一些消息.类似gmail的message模式的东西.为了达到在页面加载完成后来操作,
http://getahead.ltd.uk/dwr/browser/util/useloadingmessage
提供了一些方法.例如
<script>
function init() {
DWRUtil.useLoadingMessage();
}
if (window.addEventListener) {
window.addEventListener("load", init, false);
}
else if (window.attachEvent) {
window.attachEvent("onload", init);
}
else {
window.onload = init;
}
</script>
该参考页面给出了2个类似的文字图片实现.
DWRUtil.addOptions() 用返回的集合来填充select元素
多种实现,详细参考http://getahead.ltd.uk/dwr/browser/lists
DWRUtil.addRows() 返回的集合来填充table元素,或者tbody更为合适
原文:http://blog.chinaitlab.com/html/31/1675431-127170.html