如果设置了变量,则Ajax显示div

时间:2022-08-24 15:54:00

So I'm using jQuery to POST some items and save into the database. I have two optional fields, if they're not empty, I'd like to fadeIn in a related div in the success function. You'll notice the #picCheck.fadeIn. Right now that fades in if the stuff is submitted, but like I said, I'd like for it fadeIn only if the variable picvault from the submitted form has is set.

所以我使用jQuery来发布一些项目并保存到数据库中。我有两个可选字段,如果它们不是空的,我想在成功函数中的相关div中淡入。你会注意到#picCheck.fadeIn。现在,如果提交了这些内容就会消失,但就像我说的那样,只有在设置了来自提交表单的变量picvault时,我才会喜欢它。

Here's the jQuery:

这是jQuery:

$.ajax({
    type: "POST",
    url: "edit.php",
    data: $form.serialize(),
    success: function(){
        $('form#editForm').hide();
        $('div.success').center();
        $('div.success').fadeIn('slow').animate({opacity: 1.0}, 2000).fadeOut(1000);
        $('#picCheck'+sid).fadeIn('slow');
    }
}); // End .ajax function

2 个解决方案

#1


0  

Simply check the value of picvault in your callback function (assuming it's a checkbox)

只需在回调函数中检查picvault的值(假设它是一个复选框)

if($("#picvault").is(":checked")) {
    $('#picCheck'+sid).fadeIn('slow');
}

#2


0  

If you have access to the form, just put an if statement around your fadeIn code checking that value.

如果您有权访问表单,只需在fadeIn代码周围添加一个if语句来检查该值。

#1


0  

Simply check the value of picvault in your callback function (assuming it's a checkbox)

只需在回调函数中检查picvault的值(假设它是一个复选框)

if($("#picvault").is(":checked")) {
    $('#picCheck'+sid).fadeIn('slow');
}

#2


0  

If you have access to the form, just put an if statement around your fadeIn code checking that value.

如果您有权访问表单,只需在fadeIn代码周围添加一个if语句来检查该值。