Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.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
Javascript 如何检查输入是否不存在_Javascript_Jquery - Fatal编程技术网

Javascript 如何检查输入是否不存在

Javascript 如何检查输入是否不存在,javascript,jquery,Javascript,Jquery,我想检查这个输入是否不存在 我有这个条件来检查输入是否存在,但我想做相反的事情 if ($('input[name="urlpdfvcmd"]')) { alert('Input exist.'); } 谢谢。如果没有长度,则输入不存在: if (!$('input[name="urlpdfvcmd"]').length) { 实际上,存在性也应该用长度来检查,而不是用你的方式: if ($('input[name="urlpdfvcmd"]').length) { 如果没有长度,则输入不

我想检查这个输入是否不存在

我有这个条件来检查输入是否存在,但我想做相反的事情

if ($('input[name="urlpdfvcmd"]')) {
alert('Input exist.');
}

谢谢。

如果没有长度,则输入不存在:

if (!$('input[name="urlpdfvcmd"]').length) {
实际上,存在性也应该用长度来检查,而不是用你的方式:

if ($('input[name="urlpdfvcmd"]').length) {

如果没有长度,则输入不存在:

if (!$('input[name="urlpdfvcmd"]').length) {
实际上,存在性也应该用长度来检查,而不是用你的方式:

if ($('input[name="urlpdfvcmd"]').length) {

我知道这个问题已经问了很长时间了,但我发现支票更清楚,如下所示:

if ($("#A").is('[myattr]')) {
    // attribute exists
} else {
    // attribute does not exist
}
(如本网站所示)

编辑

if ($('#A').attr('myattr')) {
    // attribute exists
} else {
    // attribute does not exist
}
myattr
存在但为空字符串或“0”时,上述内容将属于
else
分支。如果这是一个问题,您应该在
未定义的
上显式测试:

if ($('#A').attr('myattr') !== undefined) {
    // attribute exists
} else {
    // attribute does not exist
}

我知道这个问题已经问了很长时间了,但我发现支票更清楚,如下所示:

if ($("#A").is('[myattr]')) {
    // attribute exists
} else {
    // attribute does not exist
}
(如本网站所示)

编辑

if ($('#A').attr('myattr')) {
    // attribute exists
} else {
    // attribute does not exist
}
myattr
存在但为空字符串或“0”时,上述内容将属于
else
分支。如果这是一个问题,您应该在
未定义的
上显式测试:

if ($('#A').attr('myattr') !== undefined) {
    // attribute exists
} else {
    // attribute does not exist
}

您可以使用“可见”属性检查该输入的可见性

比如说,

if ($('input[name="urlpdfvcmd"]').is(':visible')) {
    alert('Input exist.');
}

您可以使用“可见”属性检查该输入的可见性

比如说,

if ($('input[name="urlpdfvcmd"]').is(':visible')) {
    alert('Input exist.');
}

您可以尝试执行prev undefined检查:

var input = $('input[name="urlpdfvcmd"]');

    if( typeof input === 'undefined') {
       alert('input not exist')
    }
然后你可以做:

    if (!$('input[name="urlpdfvcmd"]').length || $('input[name="urlpdfvcmd"]') === "") {
        alert('Input not exist.');
    }

您可以尝试执行prev undefined检查:

var input = $('input[name="urlpdfvcmd"]');

    if( typeof input === 'undefined') {
       alert('input not exist')
    }
然后你可以做:

    if (!$('input[name="urlpdfvcmd"]').length || $('input[name="urlpdfvcmd"]') === "") {
        alert('Input not exist.');
    }

我猜它的标签是错误的,它与PHP无关。它看起来像JQuery问题。我猜它的标签是错误的,它与PHP无关。它看起来像JQuery问题。您可以这样检查$('input[name=“urlpdfvcmd”]:visible')。attr('class')此语句返回可见元素的类您可以这样检查$('input[name=“urlpdfvcmd”]:visible')。attr('class')此语句返回可见元素的类