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

发布于 2024-08-06 08:38:21 字数 963 浏览 3 评论 0原文

我希望能够禁用单选按钮的单击功能,以便我可以取消选中它。

但是,当我取消选中它时,单击仍然会触发,最终结果是一个取消选择(并相应地修改其他页面元素)的单选按钮,然后由于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愿与i 2024-08-13 08:38:21

尝试使用 halt 方法传递给事件处理程序的事件外观:

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

这将停止事件传播和默认事件行为(单击)。

Try the halt method on the event facade passed to your event handler:

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文