ToolTipDialog执行时间中“select”的“更改”事件的问题

时间:2016-07-27 08:59:14

标签: events select dojo

为什么选择更改事件执行时间将随着按钮的点击次数而增加。

HTML:

<button id="btn">click me</button>

JS

require(["dojo/_base/declare", "dojo/dom", "dojo/on", "dojo/_base/lang", "dijit/registry", "dijit/TooltipDialog", "dijit/popup","dijit/form/Select", "dojo/_base/array", "dojo/domReady!"],
  function(declare, dom, on, lang, registry, TooltipDialog, popup,Select, Array) {
  var InfoWindow= declare( // 类名省略
    TooltipDialog,
    {
      constructor: function (parameters) {
        console.log("hello");

      },

      test:function(){
        var tNode=dom.byId("btn");
        var myTooltipDialog = new TooltipDialog({
          id: 'myTooltipDialog',
          style: "width: 300px;",
          content: '<div id="tpDialog006" class="pDlg"></div><div id="selectMenu" class="right"><select name="select1" id="sel006"  data-dojo-type="dijit/form/Select"> <option  value="037" selected="selected">1</option><option class="left" value="005" >2</option><option class="left" value="007" >3</option><option   value="006">4</option></select></div>',
          onMouseLeave: function(e){
            if(registry.getEnclosingWidget(e.target).name=="select1")
              return;
            popup.close(myTooltipDialog);
          },
          onOpen:lang.hitch(this, function(e) {

          })
        });

        var sHu = registry.byId("sel006" );
        sHu.on("change", function (e) {
          alert( "value is" +sHu.value);
        });

        on(tNode,"click",function(){
          popup.open({
            popup: myTooltipDialog,
            around: dom.byId('btn')
          });
        })
        this.m1="t1";

      }

    }
  );

  var infoWindow = new InfoWindow({
  });
  infoWindow.test(); 


});

代码位于以下链接:code link

tooltipdialog节目可能存在一些问题,但不会影响要复制的问题。

1 个答案:

答案 0 :(得分:0)

再现点击是正常的,因为:

点击按钮(上图)

on(tNode,"click",function(){
   popup.open({
      popup: myTooltipDialog,
      around: dom.byId('btn')
   });
})

在每个按钮单击中,您打开Popup因此,正在执行工具提示的open功能(onOpen事件被触发),这意味着附加了更改事件再次转到sel006 select输入。

我建议你不要在工具提示onOpen事件中分配选择更改事件,并在toolTip初始化后声明它

所以代码变成了:

var myTooltipDialog = new TooltipDialog({
                    id: 'myTooltipDialog',
                    style: "width: 300px;",
                    content: '<div id="tpDialog006" class="pDlg"></div><div id="selectMenu" class="right"><select name="select1" id="sel006"  data-dojo-type="dijit/form/Select"> <option  value="037" selected="selected">1</option><option class="left" value="005" >2</option><option class="left" value="007" >3</option><option   value="006">4</option></select></div>',
    onMouseLeave: function(e){
        if(registry.getEnclosingWidget(e.target).name=="select1")
        return;
        popup.close(myTooltipDialog);
    },
    onOpen:lang.hitch(this, function(e) {
        // remove event from here                 
    })
});

var sHu = registry.byId("sel006" );

sHu.on("change", function (e) {
    alert( "value is" +sHu.value);
});

Bellow a a fiddle example:Fiddle