Dojo獲取下拉框的文本和值實(shí)例代碼

字號(hào):


    這篇文章主要介紹了Dojo獲取下拉框的文本和值實(shí)例代碼的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    Dojo
    Dojo是一個(gè)用javascript語言實(shí)現(xiàn)的開源DHTML工具包。它是在幾個(gè)項(xiàng)目捐助基礎(chǔ)上建立起來的(nWidgets,Burstlib,f(m)),這也是為什么叫它a"unified"toolkit的原因。Dojo的目標(biāo)是解決開發(fā)DHTML應(yīng)用程序遇到的那些,長期存在、歷史問題(historical problems with DHTML)??鐬g覽器問題。
    1、問題背景
    這里有一個(gè)下拉框,其中選項(xiàng)為一年四季,選中后打印下拉框的值和文本
    2、實(shí)現(xiàn)源碼
    <!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> 
    <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、實(shí)現(xiàn)結(jié)果
    (1)初始化時(shí)
    (2)點(diǎn)擊“獲取下拉框value”按鈕
    (3)點(diǎn)擊“獲取下拉框text”按鈕