Javascript JQuery用Base64替换图像(html2canvas无代理)
我对我想做的事情有一个概念,但需要帮助把这些事情组合起来 我正在找一份反馈表。它对我来说很好,但我的Flickr(跨域)照片图像不起作用 我想知道,我不能在客户端将图像转换为base64,而不是创建整个代理服务器吗?然后,一旦转换,就用base64字符串替换“数据映像”src HtmlJavascript JQuery用Base64替换图像(html2canvas无代理),javascript,jquery,html2canvas,Javascript,Jquery,Html2canvas,我对我想做的事情有一个概念,但需要帮助把这些事情组合起来 我正在找一份反馈表。它对我来说很好,但我的Flickr(跨域)照片图像不起作用 我想知道,我不能在客户端将图像转换为base64,而不是创建整个代理服务器吗?然后,一旦转换,就用base64字符串替换“数据映像”src Html <div class='container1'> <div class='box photo col3'> <a data-image='http://farm4.static.fl
<div class='container1'>
<div class='box photo col3'> <a data-image='http://farm4.static.flickr.com/3737/1530282_3bc6b9.jpg' data-toggle='lightbox' href='http://www.flickr.com/photos/1773075@N04' target='_blank'></a></div>
…..
</div>
把它放在一起:
这就是我的问题所在。我要做的是,对于div类container1中的每个数据映像,用base64字符串替换src映像,使其包含在画布中
$( "data-image" ).each( function( index, element ){
convertImgToBase64($( this ).text(), function(base64Img){
replace $(this).attr(‘data-image’) with base64 string
});
});
选择器[atribute_name]获取具有指定属性的所有元素 另外text()获取打开和关闭标记之间的文本,改为使用数据('image')
jquery.attr似乎没有什么效果,所以我尝试使用静态图像,但仍然没有看到它替换图像:$(“[数据图像]”)。每个(函数(索引,元素){$(this.attr('data-image','images/splash.png');});啊,我的错,应该是attr('src',…)。@Chris我加了一个demohank,谢谢,就是这样^1.
$( "data-image" ).each( function( index, element ){
convertImgToBase64($( this ).text(), function(base64Img){
replace $(this).attr(‘data-image’) with base64 string
});
});
$("[data-image]").each( function( index, element ){
convertImgToBase64($( this ).data('image'), function(base64Img){
$(element).attr('src', base64Img);
});
});