将javascript/jquery对话框的大小动态更改为图像大小
我有一个javascript/jquery问题 我在项目中设置了一个自定义jquery对话框。我设置了一个div和一个image标签。图像中填充了文件下载链接将javascript/jquery对话框的大小动态更改为图像大小,javascript,jquery,resize,Javascript,Jquery,Resize,我有一个javascript/jquery问题 我在项目中设置了一个自定义jquery对话框。我设置了一个div和一个image标签。图像中填充了文件下载链接 <'custom jquery dialog' runat="server" ID="dialogView" AutoOpen="false" CloseOnEscape="true" Modal="true" Title="" Visible="true" > <div runat="sever" id=
<'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 %>);
}
函数视图图像(链接){
$('#').attr('src',link)\
showDialog();
}
这可以正常工作,并显示包含图像的对话框。但是,我确实希望能够调整此对话框/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;
}
函数changeSize(){
var imageHeight=$('#')。高度;
var imageWidth=$(“#”).width;
$('#')。高度=图像高度;
$('#')。宽度=图像宽度;
$('#')。高度=图像高度;
$('#')。宽度=图像宽度;
}
上述函数在实现时添加到viewImage函数中的showDialog调用之前。这不能正常工作。我遗漏了什么吗?我不是一个ASP.NET的家伙,但是jQuery拥有的方法和属性与您在代码中使用的不同。你可以试试这个:
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);
}
函数changeSize(){
var imageHeight=$('#')。height();
var imageWidth=$('#').width();
$('#')。高度(图像高度);
$('#')。宽度(图像宽度);
$('#')。高度(图像高度);
$('#')。宽度(图像宽度);
}
您的changeSize()函数是否在外部javascript文件中?(不在页面或页眉中内联)它位于同一页面中。该函数位于viewImage函数的正下方查看此stackoverflow帖子该问题似乎有点相关: