【问题标题】:Radio Buttons in dojo frameworkdojo 框架中的单选按钮
【发布时间】:2019-04-17 12:01:17
【问题描述】:

我创建了一个 div,类似于下面的内容。其中应该创建 2 个单选按钮,每个按钮都有其独立的值。

<div>
    <input type="radio" name="colors" value="green"
        data-dojo-type="dijit/form/RadioButton"> Green
    <input type="radio" name="colors" value="red"
          data-dojo-type="dijit/form/RadioButton"> Red
</div>

我需要创建一个控制器,它在点击时应该调用一个函数,我可以在其中编写我的相关代码。

我是 Dojo 框架的新手。谁能帮帮我。

【问题讨论】:

  • 你的意思是你想以编程方式创建最后一个?

标签: html dojo dijit.layout


【解决方案1】:

在html中声明:

<input id="red_radio" />
<input id="green_radio" />

然后你可以创建一个类似的函数:

require([
    "dojo/parser",
    "dijit/form/RadioButton",
    "dijit/form/Button", // used for example purpose
    "dojo/domReady!"
], function(parser, RadioButton){
createRadios(domid, name, check, val) {
                var radioOne = new RadioButton({
                    checked: check,
                    value: val,
                    name: name,
                    onChange: (a) => {
                        if (dijit.byId(domid).checked && dijit.byId(domid).value == 'red') {
                            //code when red
                        }
                        else if (dijit.byId(domid).checked && dijit.byId(domid).value == 'green') {
                            //code when green
                        }
                    }
                }, domid);
                radioOne.startup();
            },

createRadios("red_radio", "colors", true, "red");
createRadios("green_radio", "colors", false, "green");
});

调用该函数来创建每个收音机, 我希望这对你有帮助 您还可以查看文档:https://dojotoolkit.org/reference-guide/1.10/dijit/form/RadioButton.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-07
    • 1970-01-01
    • 2012-05-15
    • 1970-01-01
    • 1970-01-01
    • 2013-09-06
    • 2017-06-25
    • 1970-01-01
    相关资源
    最近更新 更多