您好我在dojo中尝试使用CheckedMultiSelect ... 当我按下按钮时,CheckedMultiSelect中的所有选中项目都应显示在文本框中。明确编辑下面的代码...我尝试使用alertbox它不起作用
<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>
答案 0 :(得分:4)
// Dojo 1.6
dijit.byId("multiselect").get('value');
// Dojo >=1.7
require(["dijit/registry"], function(registry){
registry.byId("multiselect").get('value');
})'
文档:http://dojotoolkit.org/reference-guide/1.9/dojox/form/CheckedMultiSelect.html
答案 1 :(得分: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, 迪帕克。