javascript 中的 img 标签用于自动完成搜索
img tags in javascript for autocomplete search
我正在设计一个自动完成搜索,其结果中将包含文本和图像(工作正常)。但是,由于标准图像缓存,我的图像变得模糊。所以我想知道是否可以调整 javascript 中的图像大小,使它们看起来整洁小巧?
下面是我的 javascript 使用 img 标签的地方。
有人可以帮我解决这个问题吗?谢谢。
.data('autocomplete')._renderItem = function(ul, item) {
return $('<li>')
.data('item.autocomplete', item)
.append("<a>"+"<img src ='/account/"+item.id+"/icon/preview'/>" + item.label+"</a>")
.appendTo(ul);
只需为您的图片标签添加 CSS 属性或通过
之类的脚本更改它
image.style.width='50%';
image.style.height='auto';
通过这样做,您可以保持图像的分辨率。所以它不能失去它的质量。
希望这段代码对你有所帮助,这里我使用了 jquery UI 和内联样式
$.ui.autocomplete.prototype._renderItem = function(ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a><img src='/account/"+item.id + "/icon/preview' style='position:relative; top:30px;width:50px;height:50px;' />"+item.label+ "</a>").appendTo( ul );
};}
我正在设计一个自动完成搜索,其结果中将包含文本和图像(工作正常)。但是,由于标准图像缓存,我的图像变得模糊。所以我想知道是否可以调整 javascript 中的图像大小,使它们看起来整洁小巧?
下面是我的 javascript 使用 img 标签的地方。
有人可以帮我解决这个问题吗?谢谢。
.data('autocomplete')._renderItem = function(ul, item) {
return $('<li>')
.data('item.autocomplete', item)
.append("<a>"+"<img src ='/account/"+item.id+"/icon/preview'/>" + item.label+"</a>")
.appendTo(ul);
只需为您的图片标签添加 CSS 属性或通过
之类的脚本更改它image.style.width='50%';
image.style.height='auto';
通过这样做,您可以保持图像的分辨率。所以它不能失去它的质量。
希望这段代码对你有所帮助,这里我使用了 jquery UI 和内联样式
$.ui.autocomplete.prototype._renderItem = function(ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a><img src='/account/"+item.id + "/icon/preview' style='position:relative; top:30px;width:50px;height:50px;' />"+item.label+ "</a>").appendTo( ul );
};}