我正在将正在开发的站点转换为引导程序。在我的一个页面上,我根据用户输入动态创建图像。
我从这样的页面开始:
之后 :
用户单击其中一个杂志封面,左上角会生成一个新图像。图像的其他部分是用户在其他页面上所做的选择。
我的问题是生成代码的 javascript 在 HTML 中插入 width= 和 height= 代码。由于这会破坏引导响应图像,我想摆脱它,但我不知道如何。其他一切工作正常。
这是过程:
我从 HTML 开始:
<div id='FramePreviewDiv'>
<img class='img-responsive' alt='' id='fpS' style='padding:4px' src='' /> </a>
</div>
页面入口没有图像。生成默认图像。
当客户点击其中一个杂志封面时,就会发出请求。
getImage('fpS', buildFrameUrl ( 200 ), true);
函数 buildFrameUrl 返回如下内容:
http://www.example.com/BuildFrame.php?mNo=693&tm=C9885&mm=&bm=C9887&noMats=2&size=200&art=siv1n1-0854.jpg&ft=1&matWidth=2.0&maxWidth=200&maxHeight=400&artWidth=8.25&artHeight=11.5&isCropped=0&xStart=0&yStart=0&croppedPxWidth=&croppedPxHeight=&caw=&cah=
这是getImage的代码
function getImage(pExistingImageID, pImageURL, fShowLoading)
{
var link;
if (fShowLoading)
{
document.getElementById(pExistingImageID).src="/img/loader.gif"; // animated gif of your choice
document.getElementById(pExistingImageID).width=32;
document.getElementById(pExistingImageID).height=32;
}
var img = document.createElement('img');
img.onload = function (evt) {
document.getElementById(pExistingImageID).src=this.src;
document.getElementById(pExistingImageID).width=this.width; // this is the culprit
document.getElementById(pExistingImageID).height=this.height; // this is the culprit
};
img.src = pImageURL;
return false;
}
由此生成的 HTML 看起来像这样
<div id="FramePreviewDiv">
<img id="fpS" class="img-responsive" width="200" height="244"
src="http://www.tpfnew.com/BuildFrame.php?mNo=693&tm=C9885&mm=&bm=C9887&noMats=2&size=200&art=siv1n1-0854.jpg&ft=1&matWidth=2.0&maxWidth=200&maxHeight=400&artWidth=8.25&artHeight=11.5&isCropped=0&xStart=0&yStart=0&croppedPxWidth=&croppedPxHeight=&caw=&cah=" style="padding:4px" alt="">
</div>
width= 来自此处设置的值:
document.getElementById(pExistingImageID).width=this.width;
高度也一样。
我尝试消除该行,但这给了我来自 fShowLoading 代码的 32x32 图像。如果我从 fShowLoading 块中删除宽度和高度 =,我会得到正确尺寸的图像,但在生成的 html 中仍然具有宽度 = 和高度 =。
关于如何消除 width= 和 height= html 生成的任何想法,以便引导程序能够响应地调整图像大小?