在SO中多次询问这个问题.但我还是得不到东西.
我想从回调中获得一些价值.请查看下面的脚本以获得说明.
function foo(address){
// google map stuff
geocoder.geocode( { 'address': address}, function(results, status) {
results[0].geometry.location; // I want to return this value
})
}
foo(); //result should be results[0].geometry.location; value
Run Code Online (Sandbox Code Playgroud)
如果我试图返回该值只是"未定义".我从SO那里听了一些想法,但仍然失败了.
那些是:
function foo(address){
var returnvalue;
geocoder.geocode( { 'address': address}, function(results, status) {
returnvalue = results[0].geometry.location;
})
return returnvalue;
}
foo(); //still undefined
Run Code Online (Sandbox Code Playgroud) 我正在构建一个 jQuery 插件,它为图像添加水印(是的,我很清楚 javascript/html5 水印系统的众多缺点,但现在暂时忽略它。)每个图像的基本方法是:
现在,如果我用画布本身替换图像元素,它似乎工作正常......所有元素都出现在画布上。但是当我获得画布的 dataURL 时,除了绘制在它上面的最后一个图像之外的所有内容都会出现。我什至不介意这个插件也需要替换图像的链接,因此用数据 url(带水印)替换 hrefs。
这是当前的代码:
(function($){
$.fn.extend({
cmark: function(options) {
var defaults = {
type: 'image',
content: 'watermark.png',
filter: 'darker',
scale:300,
box: {
top : 0.5,
left : 0.5,
width : 0.75,
height : 0.75,
bgcolor : '#000000',
bgopacity : 0.5,
fgopacity : 1
},
callback_unsupported: function(obj){
return obj;
}
}
var getScale = function(w, h, scale){
ratio = Math.min(scale/w, scale/h);
scalew = Math.round(ratio*w);
scaleh = Math.round(ratio*h);
return …Run Code Online (Sandbox Code Playgroud)