简体   繁体   English

ExtJS:禁用复选框在标签单击时切换

[英]ExtJS: disable checkbox toggle on label click

I am designing a checkbox for a for and I absolutely cannot have the checkbox to toggle when the user clicks on its label, as this label contains a link to open a small infobox where the user gets to know what he or she is accepting by selecting the checkbox. 我正在为for设计一个复选框,当用户单击其标签时,我绝对不能切换该复选框,因为此标签包含一个打开小信息框的链接,用户可以通过选择该框来了解他或她接受的内容复选框。

How can I disable checkbox toggle when clicking on its label? 单击标签时如何禁用复选框切换?

The code looks simply like this (this element is inside a FormPanel items list:) 代码看起来像这样(此元素在FormPanel项目列表中:)

{ xtype:'checkbox', id: 'privacyCheck', fieldLabel: 'I have read, understood and accepted the privacy policy of ABCDE' } {xtype:'checkbox',id:'privacyCheck',fieldLabel:'我已阅读,理解并接受ABCDE的隐私政策'}

Instead of using the boxLabel property or field label on the checkbox, create a separate label object next to the checkbox. 与其在复选框上使用boxLabel属性或字段标签,不如在复选框旁边创建一个单独的标签对象。 This should make it easier to manipulate your handler for the label. 这应该使操作标签的处理程序更加容易。 Otherwise, you will need to dig through the appropriate DOM element for the boxLabel (not pretty) to get at it. 否则,您将需要为boxLabel(不是很漂亮)挖掘适当的DOM元素。

I know, this topic is rather old, but I found it, searching for a solution to the exact same problem. 我知道,这个主题比较旧,但是我找到了,正在寻找完全相同的问题的解决方案。 So I'd like to share. 所以我想分享。

I needed to modify the browsers behaviour to mimick the behaviour of a legacy site, while making said site "accessible". 我需要修改浏览器的行为,以模仿旧站点的行为,同时使该站点“可访问”。 (The for-attribute of the label tag is needed and a label without a for-attribute can not be used.) (需要label标签的for-attribute,并且不能使用没有for-attribute的标签。)

I don't know about ExtJS, but since the legacy site uses jQuery in the frontend, I solved the problem this way: 我不了解ExtJS,但是由于旧站点在前端使用jQuery,因此我通过以下方式解决了问题:

//[...]
$(document).ready(function () {
    $('.donotToogleCheckbox').click(function (event) {       
        event.preventDefault();
        // do other stuff like displaying a dialog or something
    })
});
//[...]
<label class='donotToogleCheckbox' for='myCheckbox'>DaLabel</label>
<input id='myCheckbox' name='myCheckbox' type="checkbox">
//[...]

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

相关问题 为什么此复选框上的标签为“容器”,而不允许文本与复选框本身一起被检查(以打开或关闭复选框)? - Why is the label “container” on this checkbox, NOT allowing the text to be checkable along with the checkbox itself (to toggle the checkbox on & off)? Javascript label + IE中的复选框点击问题,将复选框替换为图像 - Javascript label + checkbox click problem in IE, replacing a checkbox with an image 使用复选框+标签组合防止双击错误 - Preventing double-click bug with checkbox + label combination Vb.Net 复选框以启用和禁用单击槽形式 - Vb.Net Checkbox to enable and disable click trough form ExtJS组合加载和禁用 - ExtJS combo load and disable 编写一个大的单击切换按钮来替换单个复选框并提交按钮表单的最佳方法是什么? - Best way to code a big one-click toggle button to replace a single checkbox and submit button form? jQuery-显示/隐藏表单标签和字段以及使用复选框禁用字段? - jQuery - Show/Hide Form Label & Field plus Disable Field using checkbox? 禁用表单控件的切换 - Disable toggle on form control ExtJS-将CheckBox动态添加到窗体 - ExtJS - Dynamically add CheckBox to Form 将复选框与标签内联放置 - Place checkbox inline with label
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM