1、问题背景 这里有一个下拉框,其中选项为一年四季,选中后打印下拉框的值和文本 2、实现源码 !DOCTYPE htmlhtmlheadmeta charset="utf-8" /titledojo-获取下拉框的值和文本/titlelink rel="stylesheet
1、问题背景
这里有一个下拉框,其中选项为一年四季,选中后打印下拉框的值和文本
2、实现源码
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>dojo-获取下拉框的值和文本</title> <link rel="stylesheet" href="js/dojo/dijit/themes/claro/claro.css" /> <script type="text/javascript" src="js/jquery-1.12.4.js"></script> <script type="text/javascript" src="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 class="claro"> <input id="season" /><br> <button id="valueBtn" onclick="alert(dijit.byId('season').get('value'))">获取下拉框value</button> <button id="textBtn" onclick="alert(dijit.byId('season').get('displayedValue'))">获取下拉框text</button> </body> </html>
3、实现结果
(1)初始化时
(2)点击“获取下拉框value”按钮
(3)点击“获取下拉框text”按钮