2017-03-01 76 views
2
<div class="masterform type-selection"> 


<div class="radio"><span><input type="radio" name="feature_value_6" value="10" required=""></span></div><label>Cool</label> 



function ShowLoading() { 

var verif = true; 

$(".masterform input").each(function() { 
if($(this).val() == ""){ 
verif = false; 
} 
}); 
var radio = false; 
$(".type-selection div.radio span").each(function() { 
if($('.masterform input[type=radio]:checked').size() > 0){ 
radio = true; 
} 
}); 

if(verif == true && radio == true){ 
window.loading_screen = window.pleaseWait({ 
blabla }); } 

} 

我试过了一切,变量发送给我,但当我在无线电输入使用此验证没有任何工作。我的功能只有当我通过点击我的Safari浏览器的十字架停止提交表单时才起作用!javascript形式验证

一切工作的罚款铬,但不能让它在Safari

回答

1

工作,我清理你的代码。看起来像你只需要使用length代替$.size()

var radio = false; 
 
$(".type-selection div.radio span").each(function() { 
 
    if ($('.masterform input[type=radio]:checked').length > 0) { 
 
    radio = true; 
 
    } 
 
    console.log(radio); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="masterform type-selection"> 
 
    <div class="radio"> 
 
    <span> 
 
     <input type="radio" name="feature_value_6" value="10" required="" checked> 
 
    </span> 
 
    </div> 
 
    <label>Cool</label> 
 
</div>

+0

只是尝试同样的事情,不工作直到我通过导航器上的十字架停止页面收费 – jolo

+0

@jolo“page charge”?那是什么意思? –

+0

当页面加载 – jolo

0

尝试使用“托”的jQuery的属性,如:

$(".type-selection div.radio span input[type='radio']").each(function(elemIndex, domElement) { //Each radio 
    if($(domElement).prop('checked')){ 
     radio = true; 
    } 
}); 
+0

只是尝试相同的东西不工作,直到我停止在导航器上交叉页面充电!它的如此奇怪的一切工作正常,没有无线电检查 – jolo