2013-11-04 61 views
1

您好,我正嘗試在Dojo中使用CheckedMultiSelect ... 當我按下按鈕時,CheckedMultiSelect中的所有選中的項目應該顯示在一個文本框中..親切地編輯下面的代碼...我嘗試使用alertbox它沒有工作DOJO checkedmultiselect

<html> 
<link rel="stylesheet" href="dijit/themes/claro/claro.css"> 
<script>dojoConfig = {parseOnLoad: true}</script> 
<script src="dojo/dojo.js"></script> 
<script> 
require(["dojox/form/CheckedMultiSelect","dijit/form/Button"]); 
</script> 
<script> 
function selectcont() 
    { 
     var e=document.getElementById("multiselect"); 
     var str=e.options[e.selectedIndex].value; 
    } 
    document.write(str); 
</script> 
<body class="claro"> 
<select multiple="true" data-dojo-type="dojox/form/CheckedMultiSelect" id="multiselect" > 
     <option value="TN">Tennessee</option> 
     <option value="VA" selected="selected">Virginia</option> 
     <option value="WA" selected="selected">Washington</option> 
     <option value="FL">Florida</option> 
     <option value="CA">California</option> 
</select> 
<div> 
<button data-dojo-type="dijit/form/Button" type="button" onclick="selectcont()">click me</button> 
</div> 
</body> 
</html> 

回答

4
// Dojo 1.6  
dijit.byId("multiselect").get('value'); 

// Dojo >=1.7 
require(["dijit/registry"], function(registry){ 
    registry.byId("multiselect").get('value'); 
})' 

相關下載測試:http://download.dojotoolkit.org/release-1.9.1/dojo-release-1.9.1/dijit/tests/form/test_MultiSelect.html

文檔:http://dojotoolkit.org/reference-guide/1.9/dojox/form/CheckedMultiSelect.html

現場督S:http://livedocs.dojotoolkit.org/dijit/form/MultiSelect

+0

但如何將它添加到按鈕單擊事件 – user2918673

+0

看dojo/on – Layke

+1

在您的具體情況下,您可以使用'var value = registry.byId('multiselect')。get('value');'in你的'selectcont'函數並在任何你想要的地方使用'value',包括另一個元素的'innerHTML'。然後使用'dojo/on':'on('myButton',click,selectcont)'而不是'onclick'屬性。 –

0

謝謝大家.. 我得到了想要的輸出:

<!-- DOKO-CHECKED MULTI SELECT --> 
<html> 
<link rel="stylesheet" href="dijit/themes/claro/claro.css"> 
<style type="text/css"> 
@import "dojox/form/resources/CheckedMultiSelect.css"; 
    </style> 
<script>dojoConfig = {parseOnLoad: true}</script> 
<script src="dojo/dojo.js"></script> 
<script> 
require(["dojo/dom", "dojox/form/CheckedMultiSelect"]); 
</script> 
<script> 
function hop() 
    { 
      var total=""; 
      var a=document.getElementById("multiselect").options; 
      var b=a.length; 
      var values = new Array(); 
      for(var i=0; i < b; i++) 
     { 
      if(a[i].selected) 
      values[i]=a[i].value; 

     } 
      if(values=="") 
      alert("select Items") 
      else 
      document.getElementById("name").value=values; 
    } 
</script> 
<body class="claro"> 
<h1>DRUG INDICATIONS</h1> 
<select multiple="true" data-dojo-type="dojox.form.CheckedMultiSelect" id="multiselect" > 
     <option value="Tennessee">Tennessee</option> 
     <option value="Virginia">Virginia</option> 
     <option value="Washington">Washington</option> 
     <option value="Florida">Florida</option> 
     <option value="California">California</option> 
</select> 
<input type="button" name="goto" onClick="hop()" value="ADD"> 
<input data-dojo-type="dijit/form/TextBox" name="name" id="name"> 
</body> 
</html> 

-Regards, 迪帕克。