动态地将 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 调用之前添加的。这不能正常工作。我错过了什么吗?
I have a javascript/jquery question.
I have a custom jquery dialog box setup in my project. I set this up with a div and an image tag. The image is populated with a filedownload link.
<'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'>
That is the setup for the box itself. Here is the javascript I have to populate the box with the image depending on the link sent from a class
function viewImage(link){
$('#<%= this.theImage.ClientID %>').attr('src', link);\
showDialog(<%= this.dialogView.ClientID %>);
}
This works fine and shows the dialog box with the image in it. However, I really want to be able to size this dialog box/div. How can I change this according to the size of the image? I tried this
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;
}
The above function, when implemented, was added before the showDialog call in the viewImage function. This does not work correctly. Am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是 ASP.NET 人员,但 jQuery 有
width()
和height()
方法而不是属性就像您在代码中使用的一样。你可以试试这个:I am not a ASP.NET guy but jQuery has
width()
andheight()
methods not properties like you are using in your code. You may try this: