Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.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_Boolean Logic - Fatal编程技术网

Jquery 检查浏览器中是否存在导致脚本错误的元素

Jquery 检查浏览器中是否存在导致脚本错误的元素,jquery,boolean-logic,Jquery,Boolean Logic,我试图将Qtip插件附加到元素,前提是页面上存在包含特定文本的元素。出于某种原因,我在一个元素不存在的页面上不断收到一个脚本错误,上面说“AddTooltips()不是函数”。我的if语句有些不太正常 $(document).ready(function() { function AddTooltips() { var infoIcon = '<img class="actionItem catInfo" style="margin-left:4px" src="/images/0

我试图将Qtip插件附加到元素,前提是页面上存在包含特定文本的元素。出于某种原因,我在一个元素不存在的页面上不断收到一个脚本错误,上面说“AddTooltips()不是函数”。我的if语句有些不太正常

$(document).ready(function() {

 function AddTooltips() {
  var infoIcon = '<img class="actionItem catInfo" style="margin-left:4px" src="/images/00_Core/info.gif"/>';
  var $Age = $("div.question h3:contains('Age')");
  var $Gender = $("div.question h3:contains('Gender')");
  var $Questions = $("div.question h3:contains('Age'), div.question h3:contains('Gender')");
  $Questions.append(infoIcon);
  $.fn.qtip.styles.speStyle = { // Last part is the name of the style
   width: 400,
   border: {
    width: 2,
    radius: 6
   },
   name: 'light' // Inherit the rest of the attributes from the preset dark style
  };
  $Age.children("img.catInfo").qtip({content: 'Some Copy.', style: 'speStyle'
  });
  $Gender.children("img.catInfo").qtip({content: 'Some Different Copy.', style: 'speStyle'
  });
 }


 if ( $("div.question h3:contains('Age')").length > 0 || $("div.question h3:contains('Gender')").length > 0 ) {  
  AddTooltips();
 }
});
$(文档).ready(函数(){
函数AddTooltips(){
var infoIcon='';
变量$Age=$(“部门问题h3:包含('Age'));
变量$SEXT=$(“部门问题h3:包含('SEXT'));
变量$Questions=$(“第三部分问题:包含('年龄'),第三部分问题:包含('性别');
$Questions.append(信息图标);
$.fn.qtip.styles.speStyle={//最后一部分是样式的名称
宽度:400,
边界:{
宽度:2,
半径:6
},
名称:“light”//继承预设暗样式的其余属性
};
$Age.children(“img.catInfo”).qtip({content:'Some Copy',style:'speStyle'
});
$Gender.children(“img.catInfo”).qtip({content:'一些不同的副本',style:'speStyle'
});
}
如果($(“分区问题h3:包含('年龄')))。长度>0 | |$(“分区问题h3:包含('性别'))。长度>0){
添加工具提示();
}
});
添加工具提示()
置于dom就绪事件之外,如下所示:

function AddTooltips() {
    var infoIcon = '<img class="actionItem catInfo" style="margin-left:4px" src="/images/00_Core/info.gif"/>',
        $Age = $("div.question h3:contains('Age')"),
        $Gender = $("div.question h3:contains('Gender')"),
        $Questions = $("div.question h3:contains('Age'), div.question h3:contains('Gender')");

    $Questions.append(infoIcon);
    $.fn.qtip.styles.speStyle = { // Last part is the name of the style
        width: 400,
        border: {
            width: 2,
            radius: 6
        },
        name: 'light' // Inherit the rest of the attributes from the preset dark style
    };
    $Age.children("img.catInfo").qtip({content: 'Some Copy.', style: 'speStyle'});
    $Gender.children("img.catInfo").qtip({content: 'Some Different Copy.', style: 'speStyle'});
}

$(function() {
    if ($("div.question h3:contains('Age'), div.question h3:contains('Gender')").length) {  
        AddTooltips();
    }
});
函数AddTooltips(){
var infoIcon='',
$Age=$(“部门问题h3:包含('Age')”),
$SEXT=$(“问题h3部分:包含('SEXT')),
$Questions=$(“第三部分问题:包含('年龄'),第三部分问题:包含('性别');
$Questions.append(信息图标);
$.fn.qtip.styles.speStyle={//最后一部分是样式的名称
宽度:400,
边界:{
宽度:2,
半径:6
},
名称:“light”//继承预设暗样式的其余属性
};
$Age.children(“img.catInfo”).qtip({content:'Some Copy',style:'speStyle'});
$Gender.children(“img.catInfo”).qtip({content:'Some Different Copy',style:'speStyle'});
}
$(函数(){
如果($($第三部分问题:包含('年龄'),第三部分问题:包含('性别'))。长度){
添加工具提示();
}
});