在jquery函数中包含if

时间:2014-08-26 17:11:41

标签: jquery if-statement conditional-statements

我尝试在

中制作4 if
$('body').on('click','.imagesauvegarde', function (){}

4个条件是:

if ($(this).closest('td.block').find('td.redactor_content').redactor('destroy');){
}

if ($(this).closest('table.block').find('td.redactor_content').redactor('destroy');){
}

if ($(this).closest('div.block').find('div.redactor_content').redactor('destroy');){
}

if ($(this).closest('table.block').find('div.redactor_content').redactor('destroy');){
}

对于他们每个人,我想:

        $( ".sortable" ).sortable("enable");
        $( ".sortable1" ).sortable("enable");
        $( ".sortable2" ).sortable("enable");
        $( ".sortable3" ).sortable("enable");
        $( ".sortable4" ).sortable("enable");
        $( ".sortable5" ).sortable("enable");
        $( ".sortable6" ).sortable("enable");
        $(this).closest('table.block').find('.img-thumbnail.deplacer').css('display','inline');
        setTimeout(function(){
        var token_newsletter=$("#token_newsletter").val();
        var html=$('#blocknewsletter').html();
        $("#blocknewsletter_save").html(html);
        $("#blocknewsletter_save .bloc_gestion_titre").remove();
        $("#blocknewsletter_save .bloc_gestion_titre_logo").remove();
        $("#blocknewsletter_save .bloc_gestion_image_logo").remove();
        $("#blocknewsletter_save .bloc_gestion_image").remove();
        $("#blocknewsletter_save .bloc_gestion_image_features").remove();
        $("#blocknewsletter_save .bloc_gestion_paragraphe_large").remove();
        $("#blocknewsletter_save .bloc_gestion_paragraphe").remove();
        $("#blocknewsletter_save .bloc_gestion_vosprojets").remove();
        $("#blocknewsletter_save .deplacerabsolute").remove();
        $("#blocknewsletter_save .bloc_gestion_features").remove();
        $("#blocknewsletter_save .deplacerabsolutefeatures").remove();
        $("#blocknewsletter_save .deplacerabsolute").remove();
        $("#blocknewsletter_save .bloc_gestion_image").remove();
        $("#blocknewsletter_save .bloc_gestion_bloc_image_2colonnes").remove();
        $("#blocknewsletter_save .bloc_gestion_bloc_image_2colonnesbis").remove();
        $("#blocknewsletter_save .bloc_gestion_bloc_image_2colonnesbis").remove();
        $("#blocknewsletter_save .bloc_gestion_bloc_image_3colonnes").remove();
        $("#blocknewsletter_save .bloc_gestion_paragraphe2colonnes").remove();
        $("#blocknewsletter_save .bloc_gestion_paragraphe2colonnesbis").remove();
        $("#blocknewsletter_save .bloc_gestion_paragraphe3colonnes").remove();
        $("#blocknewsletter_save .dupliquer_trait").remove();
        var html_save=$("#blocknewsletter_save").html();
        alert (html);
        $.ajax({
                type:"POST",
                data: {action:"saveHTML",html:html_save,token_newsletter:token_newsletter},
                url: "process/ajax.php",

                });

        return false;
        }, 2000);

完整的jquery代码:

       $('body').on('click','.imagesauvegarde', function (){

       $(this).closest('td.block').find('td.redactor_content').redactor('destroy');
       $(this).closest('table.block').find('td.redactor_content').redactor('destroy');
       $(this).closest('div.block').find('div.redactor_content').redactor('destroy');
       $(this).closest('table.block').find('div.redactor_content').redactor('destroy');
        $( ".sortable" ).sortable("enable");
        $( ".sortable1" ).sortable("enable");
        $( ".sortable2" ).sortable("enable");
        $( ".sortable3" ).sortable("enable");
        $( ".sortable4" ).sortable("enable");
        $( ".sortable5" ).sortable("enable");
        $( ".sortable6" ).sortable("enable");
        $(this).closest('table.block').find('.img-thumbnail.deplacer').css('display','inline');
        setTimeout(function(){
        var token_newsletter=$("#token_newsletter").val();
        var html=$('#blocknewsletter').html();
        $("#blocknewsletter_save").html(html);
        $("#blocknewsletter_save .bloc_gestion_titre").remove();
        $("#blocknewsletter_save .bloc_gestion_titre_logo").remove();
        $("#blocknewsletter_save .bloc_gestion_image_logo").remove();
        $("#blocknewsletter_save .bloc_gestion_image").remove();
        $("#blocknewsletter_save .bloc_gestion_image_features").remove();
        $("#blocknewsletter_save .bloc_gestion_paragraphe_large").remove();
        $("#blocknewsletter_save .bloc_gestion_paragraphe").remove();
        $("#blocknewsletter_save .bloc_gestion_vosprojets").remove();
        $("#blocknewsletter_save .deplacerabsolute").remove();
        $("#blocknewsletter_save .bloc_gestion_features").remove();
        $("#blocknewsletter_save .deplacerabsolutefeatures").remove();
        $("#blocknewsletter_save .deplacerabsolute").remove();
        $("#blocknewsletter_save .bloc_gestion_image").remove();
        $("#blocknewsletter_save .bloc_gestion_bloc_image_2colonnes").remove();
        $("#blocknewsletter_save .bloc_gestion_bloc_image_2colonnesbis").remove();
        $("#blocknewsletter_save .bloc_gestion_bloc_image_2colonnesbis").remove();
        $("#blocknewsletter_save .bloc_gestion_bloc_image_3colonnes").remove();
        $("#blocknewsletter_save .bloc_gestion_paragraphe2colonnes").remove();
        $("#blocknewsletter_save .bloc_gestion_paragraphe2colonnesbis").remove();
        $("#blocknewsletter_save .bloc_gestion_paragraphe3colonnes").remove();
        $("#blocknewsletter_save .dupliquer_trait").remove();
        var html_save=$("#blocknewsletter_save").html();
        alert (html);
        $.ajax({
                type:"POST",
                data: {action:"saveHTML",html:html_save,token_newsletter:token_newsletter},
                url: "process/ajax.php",

                });

        return false;
        }, 2000);

    });

如果有人有想法? 提前谢谢。

0 个答案:

没有答案