这篇文章主要介绍了Dojo获取下拉框的文本和值实例代码的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下
Dojo
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 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”按钮