簡體   English   中英

動態將javascript / jquery對話框的大小更改為圖像的大小

[英]Dynamically change the size of a javascript/jquery dialog box to the size of an image

我有一個javascript / jquery問題。

我的項目中有一個自定義的jquery對話框設置。 我用一個div和一個圖像標簽來設置它。 該圖像填充有文件下載鏈接。

<'custom jquery dialog'  runat="server" ID="dialogView" AutoOpen="false"   CloseOnEscape="true" Modal="true" Title="" Visible="true" >
    <div runat="sever" id="imageContainer">
        <img src="" alt="Image" runat="server" id="theImage" />
    </div>
</'custom jquery dialog'>

這是盒子本身的設置。 這是JavaScript,我必須根據從類發送的鏈接用圖像填充框

function viewImage(link){
    $('#<%= this.theImage.ClientID %>').attr('src', link);\
    showDialog(<%= this.dialogView.ClientID %>);
}

這可以正常工作,並顯示其中包含圖像的對話框。 但是,我確實希望能夠調整此對話框/ div的大小。 如何根據圖像大小更改此設置? 我試過了

function changeSize(){
    var imageHeight = $('#<%= this.theImage.ClientID %>').height;
    var imageWidth = $('#<%= this.theImage.ClientID %>').width;
    $('#<%= this.dialogView.ClientID %>').height = imageHeight;
    $('#<%= this.dialogView.ClientID %>').width = imageWidth;
    $('#<%= this.imageContainer.ClientID %>').height = imageHeight;
    $('#<%= this.imageContainer.ClientID %>').width = imagewidth;
}

上面的函數在實現時被添加到viewImage函數中的showDialog調用之前。 這不能正常工作。 我想念什么嗎?

我不是ASP.NET專家,但是jQuery具有width()height() 方法,而不是您在代碼中使用的屬性 您可以嘗試以下方法:

function changeSize(){
    var imageHeight = $('#<%= this.theImage.ClientID %>').height();
    var imageWidth = $('#<%= this.theImage.ClientID %>').width();
    $('#<%= this.dialogView.ClientID %>').height(imageHeight);
    $('#<%= this.dialogView.ClientID %>').width(imageWidth);
    $('#<%= this.imageContainer.ClientID %>').height(imageHeight);
    $('#<%= this.imageContainer.ClientID %>').width(imagewidth);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM