【发布时间】:2012-11-24 01:32:43
【问题描述】:
这个问题只出现在 IE9 上。 Firefox 运行良好,其他浏览器也一样。
我在用户上传图像的文本区域上使用 TinyMCE(带有 ImageManager 插件)。 textarea 专门用于上传图片。当用户将图像上传/插入到 tinyMCE 文本区域并提交页面时 - 我编辑检查图像尺寸以确保其尺寸正确,然后才能完成表单提交。
我将 tinyMCE textarea 的 html 加载到 JQuery 对象中,然后使用 jquery 调用对象的 .attr("width") 以确保图像是所需的宽度。
问题是在 FireFox 上,它工作正常,返回图像的宽度。在 IE9 上,对 .attr("width") 的 jquery 调用返回 0(零)。
代码如下:
sString = $('#projectimage1').html(); // fetch the contents of the tinymce form field
objWork.html(sString); // load a work div with the html contents of the control
// check to see if the image has the correct dimensions
var objImage=null;
objImage = objWork.find("img:first");
alert("image html = " + objImage.html()); // this returns the correct html for the image tag, including the width
alert("image src = " + objImage.attr('src')); // this returns the correct image src
alert("image width = " + objImage.attr("width")); // this returns 0 in IE9!
我唯一能想到的可能是一个问题,就是当我在图像上“查看源代码”时它正在显示在 tinyMCE 文本区域中 - 图像标签中使用的所有 html 都是 html 编码的。所以 '
如果确实是这个问题,为什么IE9有这个问题,而FireFox没有?
如果这不是问题 - 是否有人对我如何进行/纠正有任何想法?
感谢专家!
【问题讨论】: