ajax請求的與頁面本身有的數據(頁面加載時候存在)的一個區別 – Javascript教程_JS教程_技術文章 – 程式設計聯盟

點擊彈出層,同時隱藏其他彈出層(1、隱藏所有層 2、判斷該彈出層是否顯示,如果顯示就隱藏、如果隱藏就顯示)
1、如果是ajax請求的數據,處理需要用
$("#simpleTip").click(function(e){
        hideAllProp();
        if($('#simple_cont').is(":visible")){
            $("#simple_cont").hide();
         }else{       
            $("#simple_cont").css({top:$(this).offset().top+$(this).height(),left:$(this).offset().left-18}).show();
            $("#simple_cont ul").html("");
            var data={};
            var dictionaryTable_Name="投訴類型";
            var dictionaryClass_Name="投訴服務";
            data={dictionaryTable_Name:dictionaryTable_Name,dictionaryClass_Name:dictionaryClass_Name};
            $.ajax({
                type:"POST",
                url:getDictionaryAction,
                dataType:"text",
                data:data,
                success:function(data){
                    var jsonArr=data.split("|");
                    var dataArr=eval("("+jsonArr[0]+")");
                    var elem;
                    for(var i=0,j=dataArr.length;i<j;i++){
                        $('<li complaintsType='+dataArr[i].dictionaryItem_ID+'>'+dataArr[i].itemName+'</li>').appendTo("#simple_cont ul").click(function(){
                            var complaintsType=$(this).attr("complaintsType");
                            hideAllProp();
                            $.ajax({
                                url:complaintRegist,
                                type:"post",
                                dataType:"text",
                                data:{complaintRegisterSource:1,complaintsType:complaintsType},
                                success:function(data){
                                    $(".iframeDiv").show();
                                    showModal();               
                                    $("#success_pro").css({left:$("p.rightCon").offset().left+200,top:$("p.rightCon").offset().top+100}).show();
                                    type="simple";
                                },
                                error:function(data){   
                                    $(".iframeDiv").show();
                                    showModal();
                                    $("#failure_acc").css({left:$("p.rightCon").offset().left+200,top:$("p.rightCon").offset().top+100}).show();
                                }
                            });
                        });
                    }
                },
                error:function(){
                    //hideFunPanel1(0);hideFunPanel2(0);
                     $.alert("獲取數據失敗!");
                }
            });
             //$("#simple_cont").css({left:$(this).offset().left-$("#simple_cont").width()+$(this).width(),top:$(this).offset().top+$(this).height()}).show();
             }       
         e.stopPropagation(); www.aiwalls.com
    });
click事件不能直接用$("ul li").click(function){});   因為ul li不是頁面加載時候就有的而是通過ajax請求得到

摘自 web前端wyy的專欄

發佈留言