Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.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
jqueryfind命令_Jquery_Jquery Selectors - Fatal编程技术网

jqueryfind命令

jqueryfind命令,jquery,jquery-selectors,Jquery,Jquery Selectors,使用.find()如何查找div中是否存在单选按钮或引发警报 <div id="emp_form"> </div> 您可以使用(或仅使用a)并检查以下选项: if($("#emp_form :radio").length == 0) { alert("No radio buttons found!, Crap!"); } 当然,如果您想在这种情况下执行某些操作,则有单选按钮: if($("#emp_form :radio

使用.find()如何查找div中是否存在单选按钮或引发警报

          <div id="emp_form">

          </div>

您可以使用(或仅使用a)并检查以下选项:

if($("#emp_form :radio").length == 0) {
  alert("No radio buttons found!, Crap!");
}
当然,如果您想在这种情况下执行某些操作,则有单选按钮:

if($("#emp_form :radio").length > 0) {
  //do something
} else {
  alert("No radio buttons found!, Crap!");
}
另一种选择是
$(“#emp_form”)。查找(“:radio”)。长度

您可以使用(或仅使用a)并检查以下内容:

if($("#emp_form :radio").length == 0) {
  alert("No radio buttons found!, Crap!");
}
if ( $("#emp_form").find("input[type='radio']").length >0 ) {

} else {
   alert("There is nothing");
}
当然,如果您想在这种情况下执行某些操作,则有单选按钮:

if($("#emp_form :radio").length > 0) {
  //do something
} else {
  alert("No radio buttons found!, Crap!");
}
另一种选择是
$(“#emp_form”).find(“:radio”).length

if ( $("#emp_form").find("input[type='radio']").length >0 ) {

} else {
   alert("There is nothing");
}
固定的

修复。

试试这个-

if ($('#emp_form :radio').length != 0) {
    alert('exists');
  } else {
    alert('does not exist');
  }
试试这个-

if ($('#emp_form :radio').length != 0) {
    alert('exists');
  } else {
    alert('does not exist');
  }

您的属性选择器需要紧挨着
input
,一个空格表示子体,因此当前正在查找
type=“radio”
中不存在的
元素:)您的属性选择器需要紧挨着
input
,一个空格表示子体,因此,目前这是在一个不存在的
中寻找
type=“radio”
元素:)选择器之间确实需要一个空格,单选元素没有该ID,它们在具有该ID的元素中。感谢nick(单选按钮是div#emo_表单的子元素),我忘了添加空格。选择器之间确实需要一个空格,单选元素没有该ID,它们位于具有该ID的元素内。谢谢nick(单选按钮是div#emo_表单的子元素),我忘了添加空格。