如果再次点击相同的按钮,Javascript Dojo / Dijit单选按钮点击事件将不会触发

时间:2017-05-25 23:19:14

标签: javascript dojo dijit.form

我可以使用点击事件创建Dijit单选按钮,它们工作正常。但是,当再次单击相同的按钮(即当前检查的按钮)时,点击事件不会触发。如何才能使当我再次点击当前选中的单选按钮时可以使用事件回调?

我正在使用dijit / form / RadioButton“。

我按照以下方式创建单选按钮:

var aRadioButton = new RadioButton({
  checked: someBooleanValue,
  value: someValue,
  name: someName,
  onClick: lang.hitch(this, buttonCallback) // This works, except for when same button is clicked.
});

1 个答案:

答案 0 :(得分:1)

默认情况下,Dojo不支持RadioButton的此行为。

替代文件_onClick中的函数_RadioButtonMixin.js的猴子路径,您可以直接在dom本身上添加事件侦听器,在此示例中,我在{{1}上使用focusNode }}

实例:

https://jsfiddle.net/gibbok/kwdy5gqc/

RadioButton
  require([
  "dojo/on",
  "dojo/parser",
  "dijit/form/RadioButton",
  "dijit/form/Button", // used for example purpose
  "dojo/domReady!"
], function(on, parser, RadioButton) {
  var radioOne = new RadioButton({
    checked: true,
    value: "tea",
    name: "drink"
  }, "radioOne");

  var radioTwo = new RadioButton({
    checked: false,
    value: "coffee",
    name: "drink"
  }, "radioTwo");

  var signal = on(radioOne.focusNode, "click", function(event) {
    // this code will fire when domNode is clicked
    alert('click on input tea');
  });

  var signal = on(radioTwo.focusNode, "click", function(event) {
    // this code will fire when domNode is clicked
    alert('click on input cafee');
  });


  parser.parse();
});