如何禁用 YUI 节点上的单击处理程序?
我希望能够禁用单选按钮的单击功能,以便我可以取消选中它。
但是,当我取消选中它时,单击仍然会触发,最终结果是一个取消选择(并相应地修改其他页面元素)的单选按钮,然后由于 onclick 事件而重新检查。
var clickFunction = function(e, radio, p){
var checked = radio.get("checked");
radio.set("checked", !checked);
};
this.controlNode = Y.Node.create("<input id='" + id + "' onclick='function(e){return false;}' type='radio' name='" + parent.id + "'>");
this.label = Y.Node.create("<label for='" + id + "'>" + display + "</label>");
Y.on("mousedown", clickFunction, this.label, this.controlNode, parent.controlNode);
parent.controlNode.appendChild(this.controlNode);
parent.controlNode.appendChild(this.label);
使用 mousedown 事件处理程序,因为它适用于(Windows)触摸屏上的粗手指,并且 mousedown 和 mouseup 之间的移动不构成单击。 (通过用手指点击,手指将增加和减少其在屏幕上的表面积,并且非多点触摸屏将光标置于接触点的平均位置。轻微滚动将移动光标)。
鼠标按下会冒泡,并导致依赖性评估并显示/隐藏页面上的其他控件。
我只是想撤消;我认为有另一个重置选项对于我的特定用途来说不太令人满意。如果这里没有其他结果,我将不得不使用它。
I am wanting to be able to disable the click functionality of a radio button so I can uncheck it.
However, when I uncheck it, the click still fires and the end result is a radio that unselects (and modifies other page elements accordingly), and then re-checks because of the onclick event.
var clickFunction = function(e, radio, p){
var checked = radio.get("checked");
radio.set("checked", !checked);
};
this.controlNode = Y.Node.create("<input id='" + id + "' onclick='function(e){return false;}' type='radio' name='" + parent.id + "'>");
this.label = Y.Node.create("<label for='" + id + "'>" + display + "</label>");
Y.on("mousedown", clickFunction, this.label, this.controlNode, parent.controlNode);
parent.controlNode.appendChild(this.controlNode);
parent.controlNode.appendChild(this.label);
The mousedown event handler is used, as it's for fat fingers on a (windows) touch screen, and movement between mousedown and mouseup does not constitute a click. (Throughout a tap with a finger, the finger will increase and decrease it's surface area on the screen, and a non-multitouch screen put the cursor at the average of the contact points. A slight roll will move the cursor).
The mouse down bubbles up, and results in dependency evaluation and show/hiding other controls on a page.
I simply want undo; and I think that having another reset option is less than satisfactory for my particular use. If nothing else eventuates here, I shall have to use that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
halt
方法传递给事件处理程序的事件外观:这将停止事件传播和默认事件行为(单击)。
Try the
halt
method on the event facade passed to your event handler:This will stop the event propagating and the default event behaviour (the click).