很長一段時間以來,我一直在為 jQuery Popup 對話框使用相同的方法和腳本,這對于我對合理靜態內容的要求非常有效,即高度從不重要,因為內容總是相同的。
我現在面臨的問題是我想將它用于內容現在是動態的并且高度發生變化的不同應用程式。
我已經閱讀了 jQuery 檔案,閱讀了 Stack Overflow 上的其他一些帖子,但就是無法做到這一點。總之,我想將容器/彈出視窗的高度設定為自動以適應內容。
它可能不是最好的腳本,但就是這樣:-
<script>
function GetPRComments(txt){
$.get("pur_req_comments.cfm?XReqNo=" txt, function(data) {
$("#CommentsPopup").html(data);
$("#CommentsPopup").dialog({
height: 300,
width: 465,
title: "Purchase Requisition Details: " txt,
modal: true,
dialogClass: "PRComments",
});
});
}
</script>
下面是基于上述腳本的輸出視圖。其中一個記錄有簡短的描述,另一個有更詳細的描述。我想要實作的是消除多余的空間并使內容適合。
我(非常簡單地)希望 Height: 'auto' 可以在這里解決問題,但遺憾的是這似乎無法解決問題。我有一種感覺,這可能需要重新撰寫,但不確定。我也嘗試過使用 maxWidth。
我還閱讀了("resize", "auto")但我認為這不適用于我現有的腳本?我只是無法理解這一點。
任何幫助或指示都會有所幫助。杰克

uj5u.com熱心網友回復:
考慮使用這種方法"auto":
function GetPRComments(txt){
$.get("pur_req_comments.cfm?XReqNo=" txt, function(data) {
$("#CommentsPopup").html(data).dialog({
height: "auto",
width: 465,
title: "Purchase Requisition Details: " txt,
modal: true,
dialogClass: "PRComments",
});
});
}
如果你想設定 a height,你可以計算它。
function GetPRComments(txt){
$.get("pur_req_comments.cfm?XReqNo=" txt, function(data) {
$("#CommentsPopup").html(data);
var h = $("#CommentsPopup").height();
if(h < 300){
h = 300;
}
$("#CommentsPopup").dialog({
height: h,
width: 465,
title: "Purchase Requisition Details: " txt,
modal: true,
dialogClass: "PRComments",
});
});
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/447976.html
