$wnd and $doc Calling native JavaScript with JSNI
$wnd and $doc Calling native JavaScript with JSNI
$wnd 是什么?
GWT provides the $wnd and $doc variables to refer to the window and document objects
GWT使用通过Java Native method使用它,声明一个native方法,将含有JavaScript的方法体注释。编译器将注释块内的内容逐字输出,使之与编译产生的JavaScript整合到一起。
Java调用JavaScript方法:
JSNI方法定义需要使用native关键字,并且需要在参数列表之后,结尾的分号之前定义。JSNI方法的开始使用 /*-{ , 结尾使用}-*/,例如:
public static native void alert(String msg) /*-{
$wnd.alert(msg);
}-*/;
这是gwt Window 类中的源码--一个标准的jsni 方法, 我们可以看到,方法实现就是一行简单的javascript 代码. (这里没有用 alert 或者 window.alert 的原因是: gwt 代码运行在一个iframe中,如果直接用alert或者window.alert,引用的是iframe文档,而不是host page 文档). 经过这个方法包装,以后在gwt程序中使用 " Window.alert" 实际上就是调用了javascript 的 alert 方法,当然你也可以不用这个封装, 直接实用 $wnd.alert .
当上述方法在Java中调用的时候,实际上将调用Window的alert()方法,将传入的内容打印出来。在Hosted Mode下,断点可以调协在上述方法中,可以查看传入的参数。
参考如下:
http://www.javaeye.com/topic/365678
http://www.webreference.com/programming/java/toolkits/
The GWT makes ingenious use of Java's native methods with something called the JavaScript Native Interface. You declare native methods with commented-out bodies that contain JavaScript. When those native methods are compiled, the GWT incorporates the commented JavaScript. Here's an example of such a native method:
Calling native JavaScript with JSNI
http://www.ibm.com/developerworks/java/library/j-ajax4/
Visual-effects libraries are becoming increasingly popular in Web application development, whether their effects are used to provide subtle user-interaction cues or just to add polish. I'd like to add some eye-candy to the Weather Reporter application. GWT doesn't provide this type of functionality, but its JavaScript Native Interface (JS
相关文档:
document.close();
document.open();
function jsonFormat(template, json) {
return template.replace(/\$\{(.+?)\}/g, function ($, $1) {
return json[$1];
});
}
var links = [
{ text: "人肉搜索", url: "http://renrousousuo.com" } ,
{ text: "CSDN", url: &qu ......
1,用户名不能包含空格,第一个字母不能为数字,长度控制
2,密码和验证码要相同,不能为空,等等,一些很基本的功能,但是确实挺烦人的。
javascript调试起来确实比较麻烦。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<T ......
注意:Option中的O是要大写的,不然语法报错
1.动态创建select
function createSelect(){
var mySelect = document.createElement("select");
mySelect.id = "mySelect";
  ......
理解Javascript闭包(closure)
专题 原帖 http://www.w3cgroup.com/article.asp?id=87
此文用通俗的文字介绍了Javascript闭包 。
看过后,我对javascript闭包简单的理解就是 文中第四、五段中所说的“在内存中维持一个变量,不会被GC回收”。
当然还需要学习才能深入的理解javascript闭包
一、什么是闭包?
......