官網地址:點擊打開鏈接
基礎: layer.open彈出框的幾個 重要 基本屬性
1)type:彈出層類型,代表彈出框層的類型,(這對於加載彈框內容非常重要,也是解決問題的關鍵)
可選值有:0(信息框,默認)1(頁面層)2(iframe層)3(加載層)4(tips層)
2) content:彈出框內容
問題:
使用layer.open 打開一個彈出框後,(通過屬性 content 加載彈出框中的內容,因爲我 需要在加載彈出框後,發送一個url請求動態加載數據,所以type設置爲2,那麼問題來了,當url的參數過大時,GET 請求就搞不定了,而layer默認就是使用get請求,layer又沒有參數可以設置調整爲POST。
問題示例如下:
layer.open({
type: 2,//彈出框類型
title: 'layer彈出框post傳參測試',
shadeClose: false, //點擊遮罩關閉層
area : ['60%' , '90%'],//彈出框大小
shift:1,//彈出框動畫效果
content: 'http://localhost:8080/test?param1='+p1+"param2="+p2, //發送一個請求,後臺處理數據返回到一個html頁面加載到layer彈出層中
success: function(layero, index){
}
});
解決方案:
重新回到 layer.open 的 type屬性中,因爲 type設置爲 2時,代表當前彈出層爲一個iframe,而發送的請求類型暫時無法修改(雖然我嘗試過打開layer源碼js,把GET請求的都直接修改爲POST,但沒生效),所以只能改變策略。
思路:
1),先使用ajax 發送一個post 請求獲得要展示的結果界面。
2),定義layer.open 的類型爲 1,將結果直接用以頁面層顯示。
解決示例:
$.ajax({
type: 'POST',
url: 'http://localhost:8080/test',//發送請求
data: {param1:p1,param2:p2},
dataType : "html",
success: function(result) {
var htmlCont = result;//返回的結果頁面
layer.open({
type: 1,//彈出框類型
title: '傳播層級用戶詳情',
shadeClose: false, //點擊遮罩關閉層
area : ['60%' , '90%'],
shift:1,
content: htmlCont,//將結果頁面放入layer彈出層中
success: function(layero, index){
}
});
}
});
附:layer1.0.9完整包下載