我可以使用jquery操纵css来更改背景图像与base64字符串 [英] Can i use jquery to manipulate css to change background image with base64 string
本文介绍了我可以使用jquery操纵css来更改背景图像与base64字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里是问题。我有一个base64图像字符串,通过ajax从数据库动态检索。
data:image / png; base64,iVBORw0KGgoAAAANSUhEUgAAAvsAAAJECAYAAACIHevuAAAgAElEQVR4nO3d
检索到字符串后,我想将其设置为div的背景图片
< div id =dragBox>< / div>
解决方案
try:
$('#dragBox')css('background-image','url('+ base64_string +')');
基本上,你只是把base64放在 url $ c>。
更多信息:数据URI方案Wiki < a>
Here's the problem. i've a base64 image string which is dynamically retrieved from database via ajax.
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAvsAAAJECAYAAACIHevuAAAgAElEQVR4nO3d
after retrieving the string i want to set it as the background image of a div
<div id="dragBox"></div>
解决方案
try:
$('#dragBox').css('background-image', 'url(' + base64_string + ')');
basically, you just put the base64 inside url()
.
more information:"Data URI scheme" Wiki
这篇关于我可以使用jquery操纵css来更改背景图像与base64字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文