admin管理员组文章数量:1400311
I have written an if statement in jQuery.
My code:
if($('#customer0').checked())
{
$('#shop').fadeOut();
}
else if($('#customer1').checked())
{
$('#shop').fadeIn();
}
else ($('#customer2').checked())
{
$('#shop').fadeOut();
};
When I have if (custmer0)
and else (customer1)
the fadeOut
and fadeIn
work good. But when it's customer2
(that is else statement) it is not working? What is wrong?
I have written an if statement in jQuery.
My code:
if($('#customer0').checked())
{
$('#shop').fadeOut();
}
else if($('#customer1').checked())
{
$('#shop').fadeIn();
}
else ($('#customer2').checked())
{
$('#shop').fadeOut();
};
When I have if (custmer0)
and else (customer1)
the fadeOut
and fadeIn
work good. But when it's customer2
(that is else statement) it is not working? What is wrong?
4 Answers
Reset to default 5else doesn't take any parameters. The code below is more applicable:
if($('#customer0').checked()) { $('#shop').fadeOut(); }
else if($('#customer1').checked()) { $('#shop').fadeIn(); }
else if($('#customer2').checked()) { $('#shop').fadeOut(); };
On your third else
Change
else ($('#customer2').checked())
to
else if ($('#customer2').checked())
fix you parens:
if ($('#customer0').checked()) {
$('#shop').fadeOut();
}
else {
if ($('#customer1').checked()) {
$('#shop').fadeIn();
}
else {
if($('#customer2').checked()) {
$('#shop').fadeOut();
}
}
}
The reason why you code want working is the if statement was taking the wrong else for when the if statement is false
Also you cannot have params for an else
statement
First off, the syntax for getting the value of a checkbox is:
$('#customer0').attr('checked')
Second, else
statements don't have (statement)
after them, you need to use a else if
.
if($('#customer0').attr('checked'))
{
$('#shop').fadeOut();
}
else if($('#customer1').attr('checked'))
{
$('#shop').fadeIn();
}
else if($('#customer2').attr('checked'))
{
$('#shop').fadeOut();
}
本文标签: javascriptquotelse ifquot is not working in jQueryStack Overflow
版权声明:本文标题:javascript - "else if" is not working in jQuery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744245412a2596987.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论