admin管理员组文章数量:1423156
Hi have a html code like this
<input type="text" value="quantita" id="quantita" name="quantita">
<input type="text" value="prodotto" id="prodotto" name="prodotto">
<input type="text" value="prezzo" id="prezzo" name="prezzo">
Now I'm trying to do a jquery code that add a button if the value of all these id is different from NULL
so I do this
var list = $("#prezzo", "#quantita", "#prodotto").val();
if (list!="")
{...do this...}
else
{....do nothing...}
but it doesn't work
Hi have a html code like this
<input type="text" value="quantita" id="quantita" name="quantita">
<input type="text" value="prodotto" id="prodotto" name="prodotto">
<input type="text" value="prezzo" id="prezzo" name="prezzo">
Now I'm trying to do a jquery code that add a button if the value of all these id is different from NULL
so I do this
var list = $("#prezzo", "#quantita", "#prodotto").val();
if (list!="")
{...do this...}
else
{....do nothing...}
but it doesn't work
Share Improve this question asked Oct 24, 2015 at 23:04 user4239503user4239503 2-
You need to check each element individually, not all at once with
if (list!="")
– j08691 Commented Oct 24, 2015 at 23:05 -
Syntax error at
$("#prezzo", "#quantita", "#prodotto")
? Multiple selectors should be within same string , unbroken by actual ma operator,
, inside double quotes as single selector ; e.g.,$("#prezzo, #quantita, #prodotto")
– guest271314 Commented Oct 24, 2015 at 23:22
2 Answers
Reset to default 3You could do it like this instead
var list = $("#prezzo, #quantita, #prodotto").filter(function() {
return this.value === "";
}).length === 0;
if (list) { // All values set
assuming you meant the value is an empty string, as in no value set, and not actually the string NULL
?
$("#prezzo,#quantita,#prodotto").each(function()
{
if ($(this).val() !="" )
{}
else
{}
});
本文标签: javascriptjquery selector on multiple idStack Overflow
版权声明:本文标题:javascript - jquery selector on multiple id - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745385433a2656354.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论