简体   繁体   English

如何在YUI节点上禁用点击处理程序?

[英]How do I disable the click handler on a YUI Node?

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. 但是,当我取消选中它时,仍会触发单击,最终结果是单选取消选中(并相应地修改其他页面元素),然后由于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);

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. 使用mousedown事件处理程序是因为它用于(windows)触摸屏上的胖手指,并且mousedown和mouseup之间的移动并不构成单击。 (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. 如果没有其他结果,我将不得不使用它。

Try the halt method on the event facade passed to your event handler: 在传递给事件处理程序的事件外观上尝试使用halt方法

this.controlNode = Y.Node.create("<input id='" + id + "' type='radio' name='" + parent.id + "'>");
this.controlNode.on("click", function(e) { e.halt(); });

This will stop the event propagating and the default event behaviour (the click). 这将停止事件传播和默认事件行为(单击)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM