jQuery使用一个复选框以编程方式取消选中另一个 [英] JQuery using one checkbox to uncheck another programatically

查看:193
本文介绍了jQuery使用一个复选框以编程方式取消选中另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个脚本,其中一个复选框将取消选中另一个复选框.尽管所有数据都是以编程方式加载的,但是这有点复杂.因此,如果未选中此复选框,则过程将采用其src值,然后遍历其他输入并找到标题为'RQlevel'+单击元素的src值的输入,并将其设置为未选中.

I'm after a script where one checkbox will uncheck another. It is a bit complicated though as all the data is loaded programatically. So if a checkbox is unchecked the procedure is to take its src value, then go through the other inputs and find inputs that have a title of 'RQlevel' + the src value of the clicked elements and set it to unchecked.

这是当前代码.

function levels() {
  var test = $(this).attr('src'); 
  if ($(this).is(':not(:checked)')) { 
    $(':input').each(function() { 
      if ($(this).attr('title') === ('RQLevel' + test)) {
        $(this).removeAttr('checked');
      }
    });
  }
}

这里有一个工作示例,它将说明问题http://jsfiddle.net/V8FeW/7/ 如果同时选中了两个框,然后未选中第一个框,则第二个框也应与之对应.

There is a working example here that will illustrate the issue http://jsfiddle.net/V8FeW/7/ If both boxes are checked and the first box is then unchecked it should take the second box with it.

奇妙

推荐答案

function levels() {
  var test = $(this).attr('src'); 
  if (!this.checked)
     $('input:checkbox[title=RQlevel' + test + ']').removeAttr('checked');
}

$(function() {
    $('input:checkbox').bind('change', levels);
});

演示: http://jsfiddle.net/V8FeW/12/

这篇关于jQuery使用一个复选框以编程方式取消选中另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆