Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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
逻辑and运算符在javascript中工作不正常_Javascript_Jquery_Operators - Fatal编程技术网

逻辑and运算符在javascript中工作不正常

逻辑and运算符在javascript中工作不正常,javascript,jquery,operators,Javascript,Jquery,Operators,我正在检查documnet.ready中的某些条件,&&运算符不工作 代码片段 LBL值为空 $(function () { var lblValue = $("#lblRadioText").text(); if (lblValue.length > 0 && hasWhiteSpace(lblValue) > 0) { $("#rdExportLastTime").css('display', 'inline'); } });

我正在检查documnet.ready中的某些条件,&&运算符不工作 代码片段 LBL值为空

$(function () {
 var lblValue = $("#lblRadioText").text();
    if (lblValue.length > 0 && hasWhiteSpace(lblValue) > 0) {
        $("#rdExportLastTime").css('display', 'inline');
    }
});

function hasWhiteSpace(text) {
    return text.indexOf(' ') >= 0;
}

你能告诉我怎么了吗。

你正在检查你的布尔值是否大于0

您不需要第二个
>0

if (lblValue.length > 0 && hasWhiteSpace(lblValue)) {
    $("#rdExportLastTime").css('display', 'inline');
}
实际上,这对手术没有任何影响,但仍然不需要

代码对我来说似乎很好(稍微适应测试):
您正在尝试检查布尔值是否大于0

您不需要第二个
>0

if (lblValue.length > 0 && hasWhiteSpace(lblValue)) {
    $("#rdExportLastTime").css('display', 'inline');
}
实际上,这对手术没有任何影响,但仍然不需要

代码对我来说似乎工作得很好(稍微适合测试):

您正在从
haswitespace()
返回布尔值,因此您应该跳过条件中的
>0

您正在从
haswitespace()
返回布尔值,因此您应该跳过条件中的
>0

您确定失败的是运算符
&

如果将代码重写为:

var lblNotZero = lblValue.length > 0;
var hasWhiteSpace = hasWhiteSpace(lblValue) > 0;
if(lblNotZero && hasWhiteSpace)
{
  $("#rdExportLastTime").css('display', 'inline');
}
现在设置一个断点(或使用
alert
输出)以检查
lblNotZero
haswitespace
的值


每当你怀疑诸如
和&
之类的语言基础不能正常工作时,请重新思考。这些都经过了非常好的测试。

您确定是操作员
&&
失败了吗

如果将代码重写为:

var lblNotZero = lblValue.length > 0;
var hasWhiteSpace = hasWhiteSpace(lblValue) > 0;
if(lblNotZero && hasWhiteSpace)
{
  $("#rdExportLastTime").css('display', 'inline');
}
现在设置一个断点(或使用
alert
输出)以检查
lblNotZero
haswitespace
的值

每当你怀疑诸如
和&
之类的语言基础不能正常工作时,请重新思考。这些都经过了很好的测试。

尝试
if((lblValue.length>0)和&(haswitespace(lblValue.length>0)){
这样两个语句都被括在它们自己的括号中。试试这个…如果(lblValue.length>0和(haswitespace(lblValue)>0)){尝试
if((lblValue.length>0)和&(haswitespace(lblValue)>0)){
以便两个语句都包含在各自的括号内。如果(lblValue.length>0&(haswitespace(lblValue)>0))尝试此操作{