Dojo是一个用javascript语言实现的开源DHTML工具包。它是在几个项目捐助基础上建立起来的(nWidgets,Burstlib,f(m)),这也是为什么叫它a"unified"toolkit的原因。Dojo的目标是解决开发DHTML应用程序遇到的那些,长期存在、历史问题(historical problems with DHTML)。跨浏览器问题。
1、问题背景
这里有一个下拉框,其中选项为一年四季,选中后打印下拉框的值和文本
2、实现源码
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>dojo-获取下拉框的值和文本</title> <link href="https://www.jb51.net/js/dojo/dijit/themes/claro/claro.css" /> <script type="text/javascript" src="https://www.jb51.net/js/jquery-1.12.4.js"></script> <script type="text/javascript" src="https://www.jb51.net/js/dojo/dojo/dojo.js"></script> <style> #season{ width:200px; } </style> <script> dojoConfig={async:true,parseOnLoad:true} </script> <script> require([ "dojo/store/Memory", "dijit/form/FilteringSelect", "dojo/domReady!" ], function(Memory, FilteringSelect){ var seasonStore = new Memory({ data: [ {name:"春季", id:"spring"}, {name:"夏季", id:"summer"}, {name:"秋季", id:"autumn"}, {name:"冬季", id:"winter"} ] }); var seasonSelect = new FilteringSelect({ id: "season", name: "season", value: "spring", store: seasonStore, searchAttr: "name" }, "season").startup(); }); </script> </head> <body> <input /><br> <button>获取下拉框value</button> <button>获取下拉框text</button> </body> </html>
3、实现结果
(1)初始化时
(2)点击“获取下拉框value”按钮
(3)点击“获取下拉框text”按钮
您可能感兴趣的文章: