仅当启用复选框 A 时才启用复选框 B,反之亦然

发布于 2024-08-15 07:35:44 字数 397 浏览 2 评论 0原文

我有两列带有可预测名称的复选框。当 a 列中的复选框未选中时,如何禁用 B 列中的复选框,并且仅在启用第一个复选框 a 时才启用它?

 <dmf:checkbox 
 name="someNameAColumnNumber"
 value="true" 
 onclick = "enableColumnBCheckBox" runatclient="true" 
 />

是否有类似 on checkvalue = true 将等效复选框 B 设置为 true 以及相反的方法?

编辑复选框不在表单中。它们位于嵌套表中。
EDIT2 应该只在 IE6 中工作(我知道......)而不是寻求跨浏览器兼容性

I have a two columns of checkboxes with predictable names. How can I disable a checkbox in column B when the ones in column a is unchecked and only enable it when the first the checkbox a is enabled?

 <dmf:checkbox 
 name="someNameAColumnNumber"
 value="true" 
 onclick = "enableColumnBCheckBox" runatclient="true" 
 />

Is there something like on checkvalue = true set equivalent checkbox B to true and the other way around?

EDIT the checkboxes are not in a form.. they are in a nested table.
EDIT2 should work only in IE6 (I know....) not looking for cross browser compatibility

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

沉鱼一梦 2024-08-22 07:35:44

您当前使用任何 javascript 框架吗?如果没有,我推荐 jQuery。这可以用纯 JavaScript 来完成,并且很容易获得几乎跨浏览器的支持,但对于真正的跨浏览器支持,我绝对建议使用现有的框架。假设 jQuery:

$('#checkboxA').click(function() {
    $('#checkboxB')[0].disabled = !this.checked;
});

are you using any javascript framework currently? if not, i recommend jQuery. this could be done in pure javascript, and it'd be pretty easy to get almost-crossbrowser-support, but for real crossbrowser support, i definitely recommend using an existing framework. assuming jQuery:

$('#checkboxA').click(function() {
    $('#checkboxB')[0].disabled = !this.checked;
});
若能看破又如何 2024-08-22 07:35:44

找到了一种作为 onclick 事件工作的方法。

function toggleCheckBoxB(source) {

           var cbAID= source.id;

            var cbBID;
            cbBID= cbAID.replace("A", "B");


            if ( source.checked == 1 ) 
            {
                document.getElementById(cbBID).disabled = false;
            }
            else 
            {
                document.getElementById(cbBID).disabled = true;
                document.getElementById(cbBID).checked = 0;
            }

         }

Figured out a way that works as onclick event.

function toggleCheckBoxB(source) {

           var cbAID= source.id;

            var cbBID;
            cbBID= cbAID.replace("A", "B");


            if ( source.checked == 1 ) 
            {
                document.getElementById(cbBID).disabled = false;
            }
            else 
            {
                document.getElementById(cbBID).disabled = true;
                document.getElementById(cbBID).checked = 0;
            }

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