<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HelloWorld.aspx.cs" Inherits="DojoTest.HelloWorld" %> <!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 runat="server"> <title></title> <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.7.2/dojo/dojo.js" djconfig="parseOnLoad:true" type="text/javascript"></script> <link href="Dojo/dijit/themes/tundra/tundra.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> dojo.require("dojo.parser"); dojo.require("dijit.form.TextBox"); dojo.require("dijit.form.Button"); function init() { dojo.connect(dijit.byId("mybutton").domNode, "onclick", "login"); } function login() { if (dijit.byId("myname").value == "1" && dijit.byId("mypassword").value == "1") alert("Hello World Dojo"); else { dijit.byId("myname").setValue(""); dijit.byId("mypassword").setValue(""); alert("Erro Name or Password"); } } dojo.addOnLoad(init); </script> </head> <body class="tundra"> <form id="form" runat="server"> <div> UserName: <input type="text" length="20" id="myname" dojotype="dijit.form.TextBox"> <br> PassWord: <input type="password" length="20" id="mypassword" dojotype="dijit.form.TextBox"> <br> <div id="mybutton" dojotype="dijit.form.Button"> Submit</div> </div> </form> </body> </html>
firebug总是报dijit.byId("myname") is undefined,这个错误,不知道哪里的问题。
后来又好了,但是点击submit按钮,会弹出两次相同的警告框
我是根据这个网页http://www.bianceng.cn/webkf/Dojo/201007/18148_3.htm上的代码敲的,哪位大哥帮帮忙啊。
其实楼主可以关注一下,jquery 这个JS框架。
呵呵,就是想玩玩DOJO
DOM还没加载完吧,domReady!
dojotype 换成 data-dojo-type
dojo1.6以后就 data-dojo-type取代了dojoType