Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 访问每个内部的原始对象_Javascript_Jquery - Fatal编程技术网

Javascript 访问每个内部的原始对象

Javascript 访问每个内部的原始对象,javascript,jquery,Javascript,Jquery,我想勾选或取消勾选所有复选框,下面的代码适合我 $( '#chkboxall' ).live( 'change', function() { objs=$(document).find('#chkbox'); objs.each(function(){ $(this).attr( 'checked', $(this).is( ':ch

我想勾选或取消勾选所有复选框,下面的代码适合我

 $( '#chkboxall' ).live( 'change', function() {

                                objs=$(document).find('#chkbox');
                objs.each(function(){
                                $(this).attr( 'checked', $(this).is( ':checked' ) ? '' : 'checked' );
            });
                 });
但不是使用
$(this).is(':checked')?':选中“
我想获取我已选中ie状态$(“#chkboxal”)的原始复选框的状态。我怎样才能在每一个里面做到这一点


Krishnik

您可以在不使用here的情况下缩短它(因为它已经可以在集合中的每个元素上运行):

但是,这是无效的,您有一个重复的
chkbox
id
属性,该属性无效。为这些元素指定一个类,如下所示:

<input name="blah" class="chkbox" type="checkbox" />
$('#chkboxall').live('change', function() {
  var thing = this;
  $('.chkbox').each(function(){
    //thing = the outer this, the #chkboxall element
  });
});

对于在不同情况下发现此问题的其他人,要获取对内部“outer
this
”的引用,只需设置一个变量,如下所示:

<input name="blah" class="chkbox" type="checkbox" />
$('#chkboxall').live('change', function() {
  var thing = this;
  $('.chkbox').each(function(){
    //thing = the outer this, the #chkboxall element
  });
});

非常感谢Nick的工作,我已经更新了html标记,现在我使用类而不是id。再次感谢。