0 ) { $(":text[value=]").css('background'-6ren">
gpt4 book ai didi

javascript - 输入:empty detects empty fields when there are none

转载 作者:行者123 更新时间:2023-11-28 16:25:33 25 4
gpt4 key购买 nike

使用下面的内容,我检查每个输入字段是否为空

  if ( $("input:empty").length > 0 )
{
$(":text[value=]").css('background', 'rgb(255,220,200)');
$(":text[value!=]").css('background', 'rgb(255,255,255)');
alert('One or more fields are not completed')
e.preventDefault();
return false;
}

即使所有字段都已满,我仍然会收到警报。这里有什么问题?没有字段突出显示。我确实尝试提取它是哪个字段,但它什么也没返回。

最佳答案

:empty 并不表示输入是否有内容。它指的是节点是否有子节点。因为我不认为您在输入标签中放置了任何内容,所以它工作得很好;)

来自docs :

Description: Select all elements that have no children (including text nodes).

尝试 if ( $('input:text[value=""]').length > 0 )

example

关于javascript - 输入:empty detects empty fields when there are none,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8176424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com