dojo -- it is critical to pull in "dojo/domReady!&am
Issue: Can not get handler of an element by using dojo.byId(“element id”) ; You want to add an event to a button,code goes like this: <script> require(["dojo","dojo/on","dijit/registry","dojo/dom","dojox/mobile","dojox/mobile/parser","dojox/mobile/SwapView","dojox/mobile/PageIndicator","dojox/mobile/Heading","dojox/mobile/ScrollableView","dojox/mobile/EdgeToEdgeList","dojox/mobile/Button” ],function(dojo,on,registry,dom){ var handler = dojo.byId("btn"); on(handler,"click",function(e){ alert("i am clicked"); }); }); </script> <script type="text/javascript" src="engmain.js"></script> </head> <body style="visibility:hidden"> <div id="mainview" class="mainview" data-dojo-type="dojox/mobile/ScrollableView"> <button id="btn" data-dojo-type="dojox/mobile/Button">click me <img src="images/bottomarrow.png"/> </button> <div id="result" ></div> maincontent </div> </body> No matter how hard you clicked the button,the button just did not give you any response. And you will see this in your debugging environment (FireBug) – target is null
Possible Cause: DOM tree didn't ready when dojo.byId(“elementID” executed,so the element you specified cannot be identified. Reference: http://www.jetwu.cn/archives/101
Solution: Ensure that you pull in dojo/domReady! when you need to do something with element of the DOM tree.
The code is as below,for your reference.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>slip view</title> <link rel="stylesheet" href=""> <script type="text/javascript" src="dojox/mobile/deviceTheme.js"></script> <script type="text/javascript" src="dojo/dojo.js" data-dojo-config="isDebug:false,parSEOnLoad: true,debugAtAllCosts:false"></script> <script> require(["dojo","dojox/mobile/Button","dojo/domReady!" ],dom){ var handler = dojo.byId("btn"); on(handler,function(e){ alert("i am clicked"); }); }); </script> <script type="text/javascript" src="engmain.js"></script> </head> <body style="visibility:hidden"> <div id="mainview" class="mainview" data-dojo-type="dojox/mobile/ScrollableView"> <button id="btn" data-dojo-type="dojox/mobile/Button">click me <img src="images/bottomarrow.png"/> </button> <div id="result" ></div> main content </div> </body> </html> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- postgresql – 创建指向视图的外表
- objective-c – 检测UISlider的触摸?
- ruby-on-rails – 什么是“循环参数引用”错误,with active
- ruby-on-rails – Rails路由依赖于当前用户
- c# – Windows 10上的.NET FontFamily内存泄漏
- cocos2d-x的内存管理机制release(),retain(),autorelease()
- iphone – 部分内的部分 – UITableView –
- C语言正则表达式
- ruby-on-rails – Heroku:PG ::错误:错误:关系权限被拒绝
- ruby-on-rails – 将Node.js设置为$PATH(Ubuntu 12.04)