0
我有一个javascript/jquery问题。动态地将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调用之前添加了。这不正确。我错过了什么吗?
你的changeSize()函数是否在外部javascript文件中? (不在网页或标题中内嵌) – Adrian 2010-10-25 17:23:06
它位于同一页面中。该函数直接位于viewImage函数下面 – Tom 2010-10-25 17:24:16
看看这个stackoverflow帖子看起来问题有点相关:http://stackoverflow.com/questions/318630/get-real-image-width-and-height-with-javascript -in野生动物园铬 – Adrian 2010-10-25 17:29:54