当使用多个选择器时,如何使用此关键字选择每个选择器?

时间:2016-12-03 16:37:24

标签: javascript jquery css

我对jquery不太了解,所以请帮助我知道我们是否可以使用'这个'用于选择多个选择器的关键字,或选择以下函数中选择器的任何替代选项:

JS

$('.calsub').click(function(){
    var cRow=0,cCol=0;
    var arrA = new Array(arow);
    var arrB = new Array(acol);
    for(cRow=0;cRow<acol;cRow++)
    {
        arrA[cRow] = new Array(acol);
        arrB[cRow] = new Array(acol);
    }
    cRow=cCol=0;.matboxB .ipbox
    $('.matboxA .ipbox, .matboxB .ipbox').each(function(){
        if(this.value){
            arrA[cRow][cCol] = this.value;
            cCol++;
            if(cCol==acol){
                cCol=0;
                cRow++;
            }
        }
        else{
            $(this).css('box-shadow','0 0 1px 2px #ff574b');
        }
        if(cRow==arow){
            return false;
        }
    });cRow=0;cCol=0;
});

HTML

<div class="matboxA" style="max-width: 270px;">
     <input class="ipbox" id="a00" type="text">
     <input class="ipbox" id="a01" type="text">
     <input class="ipbox" id="a02" type="text"> 
</div> 
<div class="matboxB" style="max-width: 270px;"> 
    <input class="ipbox" id="b00" type="text"> 
    <input class="ipbox" id="b01" type="text"> 
    <input class="ipbox" id="b02" type="text"> 
</div>

通过使用上面的JS函数,我只能选择.matboxA .ipbox内的元素。使用this关键字。如何选择&#39; .matboxB .ipbox&#39;中的元素。请帮帮我。

1 个答案:

答案 0 :(得分:1)

当选择一个元素并执行一个过程时,jQuery会应用this参数。要选择此范围内的元素,可以使用jQuery find()方法。

$('.matboxA .ipbox, .matboxB .ipbox').each(function(){

   var innerElement = $(this).find('selector');

};