Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.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
Jquery 如何检查表单是否包含单选按钮?_Jquery - Fatal编程技术网

Jquery 如何检查表单是否包含单选按钮?

Jquery 如何检查表单是否包含单选按钮?,jquery,Jquery,我有一个表单,其中表单元素动态显示。我需要检查表单是否包含单选按钮 你可以这样做: if ($('#myform').find(':radio').length) { // do something if found alert("Found "+$('#myform').find(':radio').length+" radio buttons."); } if($(":radio", "#myform").length){ // Bingo, I got it

我有一个表单,其中表单元素动态显示。我需要检查表单是否包含单选按钮

你可以这样做:

if ($('#myform').find(':radio').length) {
    // do something if found
    alert("Found "+$('#myform').find(':radio').length+" radio buttons.");
}
if($(":radio", "#myform").length){
    // Bingo, I got it
    // do something
}

只需将您的单选按钮状态检查代码委托给document…Ex
$(document).on('event','selector',function(){})
检查:
if($('form').find(':radio').length)
谢谢,效果很好。