[英]Condition IF isnt working properly
在此代碼中,我將比較單擊的錨點是否與表單的id字符串相比具有不同的rel屬性字符串。
$('.title a').each(function(i){
$('.title a:eq('+i+')').click(function(e){
e.preventDefault();
$('.title a').removeClass('active');
$(this).addClass('active');
var rel = $(this).attr('rel'),
formId = $('form').attr('id');
if (formId!=rel) {
$('form[id!='+rel+']').fadeOut(200, function(){
$('form[id='+rel+']').fadeIn(200);
});
}
});
});
我第一次點擊,效果很好。 但如果我再次點擊它不會工作,我無法找到問題,有人可以幫助我嗎?
jsfiddle: http : //jsfiddle.net/z4MMw/
您可以嘗試:
$('.title a').click(function(e){
e.preventDefault();
$('.title a').removeClass('active');
$(this).addClass('active');
var rel = $(this).attr('rel');
$('form#' + rel).fadeIn(200, function(){
$('form:not(#' + rel + ')').fadeOut(200);
});
});
我已經倒退了,所以如果有一個具有給定ID的表單,它將會淡化,否則會發生任何事情。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.