找出所有图像是否有课程

时间:2013-11-25 16:44:39

标签: javascript jquery html css class

HTML:

<div class="regform"><input id="username" type="text" name="username" placeholder="Username" required><h3 class="check"><img src=''/></h3></div>
<div class="regform"><input id="password" type="password" name="password" placeholder="Password" required><h3 class="check"><img src=''/></h3></div>
<div class="regform"><input id="password2" type="password" name="password2" placeholder="Re password" required><h3 class="check"><img src=''/></h3></div>
<div class="regform"><input id="email" type="text" name="email" placeholder="E-mail" required><h3 class="check"><img src=''/></h3></div>

JS:

        $('#send').click(function(){
    var classs = $(".check").find('img');
    if(classs.hasClass("yes")){
        alert("Everything is correct");
    }else{
        alert("Something is wrong");
    }

});

我想检查一下,如果所有“.check”图像都有“是”等级。

3 个答案:

答案 0 :(得分:7)

var dotheyallhavetheclass = $('.check img:not(.yes)').length===0;

答案 1 :(得分:0)

.......或.............

var dotheyallhaveyesclass = (($('img.check').length == $('img.yes').length)) ? 1 : 0);

答案 2 :(得分:0)

这是纯粹的Javascript解决方案:以下演示:http://jsbin.com/ucoPEBEv/1/

e = document.getElementsByClassName('check');
error = false;
for (j = 0; j < e.length; j++){
   imgs = e[j].getElementsByTagName('img');    
      for (i = 0; i < imgs.length; i++){
          if (imgs[i].className != 'yes'){
             error = true;
             break; 
           } 
      }
  }
if (error){
      alert('Some Thing Wrong');
    }
else{
      alert('Every Thing Well!');
    }