我正在尝试写一些代码,在加载新内容时用占位符替换旧内容(通过ajax)。
<div id="target">
...
</div>在ajax请求-响应周期中,我希望用“正在加载”消息或图像替换目标div的内容。
到目前为止,这很简单...
然而,在某些情况下,目标是小的,而在其他情况下,目标是大的。在这两种情况下,我都不希望目标div的大小改变或出现滚动条。如果加载消息或图像需要裁剪,那就裁剪吧。
在整个过程中,' target‘div的签名(id,class,style)必须保持不变,我不能在目标div上设置width+height。
我不想依赖于在接收到新内容时执行的额外代码。
如果只使用基本的javascript/dhtml和/或prototype-js,您将如何实现这一点?
谢谢你,p。
发布于 2010-09-13 12:33:57
// prototype
Object.prototype.updateFixedSizeHtml = function(html)
{
this.innerHTML = "<div style='width:" + this.clientWidth + "px;height:" + this.clientHeight + "px;overflow:hidden;display:block;padding:0;border:0;margin:0'>" + html + "</div>";
}
// usage
document.getElementById('target').updateFixedSizeHtml('New Content');https://stackoverflow.com/questions/3697721
复制相似问题