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
Add a ment  | 

2 Answers 2

Reset to default 3

You 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