创建类似计算器的对话框,我注意到快速点击IE中的按钮将不两次点击事件(Chrome / FF按预期工作),而是抛出click事件,然后是双击事件。试验一些简单的代码,我基本上想要复制这种行为:
<script language=javascript>
function minus(num)
{
var i = document.getElementById('0001');
if (i.value > 1)
{
i.value -= num;
return true;
}
}
</script>
<input type="button" onclick="minus(1);" ondblclick="minus(1);" value="minus">
<input type="text" id="0001" name="0001" value=10>
我需要在ExtJS 3.1中这样做,但我的努力受到了阻碍。这是我尝试过的代码:
Button btn = new Ext.Button(new ButtonConfig()
.text(text)
.tooltip(tooltip)
.tooltipType("title")
.scope(this)
.handler(delgateFunction)
.x(x)
.y(y)
.tabIndex(_tabIndex++)
.width(width).height(height)
.ToDictionary());
btn.addListener("mouseenter", new EventHandler(mouseHandler));
btn.addListener("mouseover", new EventHandler(mouseHandler));
btn.addListener("mouseout", new EventHandler(mouseLeave));
if (Ext.isIE)
{
//btn.on("dblclick", new EventHandler(DoubleClick));
//btn.addListener("dblclick", new EventHandler(DoubleClick));
//btn.addListener("ondblclick", new EventHandler(DoubleClick));
}
这三条线中的任何一条似乎都不起作用。有什么建议吗?
答案 0 :(得分:0)
在渲染按钮后尝试以下操作:
btn.el.on("dblclick", new EventHandler(DoubleClick));
Ext.Button本身没有“dblclick”事件(检查api),而它的底层el(Ext.Element)有。
完整样本:
new Ext.Button({id:'btn', text:'dblclick', renderTo:Ext.getBody() });
Ext.getCmp('btn').el.on('dblclick', function(){alert('db click');});
答案 1 :(得分:0)
先生。朱带领我找到了正确的答案:
Events.AddEvent(_zeroBtn.getEl().dom, "dblclick", DoubleClickZero);