javascript在条件中使用.html作为字符串来获取值
假设我有:javascript在条件中使用.html作为字符串来获取值,javascript,jquery,Javascript,Jquery,假设我有: alert($('#child_check').html()); if($('#child_check').html() != "Select..." || $('.funnel_items').val() == "5" || $('.funnel_items_sub').val() != "Select..."){ return true; }else{ alert("N
alert($('#child_check').html());
if($('#child_check').html() != "Select..." || $('.funnel_items').val() == "5" || $('.funnel_items_sub').val() != "Select..."){
return true;
}else{
alert("No Sub category selected!");
return false;
}
.html返回:
No available selection for this action.
如何检查.html是否等于输入的字符串,因为如果我向$('#test').html()发出警报,它包含该字符串,但条件不返回true,所以我想知道这段代码有什么问题
另外,是否真的不可能使用.html值作为codi的字符串比较
谢谢我想您正在尝试查看.html()的结果是否包含另一个字符串
将
.html()
中的返回值与另一个字符串进行比较应该可以正常工作。问题可能是您的条件错误,或者返回的.html()
实际上不匹配。如果没有看到HTML,就很难说。添加了.htmlyes返回的值,我试图找到.HTML是否包含字符串“此操作没有可用的选择”
var haystack = $('#foo').html();
var needle = 'No available selection for this action.';
if (haystack.indexOf(needle) !== -1) { // If needle is inside haystack
return true;
} else {
return false;
}