dojo-获取下拉框的值和文本
Posted 翱翔天地
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了dojo-获取下拉框的值和文本相关的知识,希望对你有一定的参考价值。
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" οnclick="alert(dijit.byId('season').get('value'))">获取下拉框value</button>
<button id="textBtn" οnclick="alert(dijit.byId('season').get('displayedValue'))">获取下拉框text</button>
</body>
</html>
3、实现结果
(1)初始化时
(2)点击“获取下拉框value”按钮
(3)点击“获取下拉框text”按钮
以上是关于dojo-获取下拉框的值和文本的主要内容,如果未能解决你的问题,请参考以下文章