我在我的应用程序中使用 Jcrop 插件 (Jquery)。我决定使用一些 ajax 解决方案,但是在将值传递给函数时遇到了问题。我不知道是我缺乏 JavaScript 技能还是 Jcrop 问题。这是代码:
jQuery(window).load(function(){
jQuery('#cropbox').Jcrop({
onChange: showPreview,
onSelect: showPreview,
aspectRatio: 1
});
});
// Our simple event handler, called from onChange and onSelect
// event handlers, as per the Jcrop invocation above
function showPreview(coords)
{
if (parseInt(coords.w) > 0)
{
var rx = 100 / coords.w;
var ry = 100 / coords.h;
jQuery('#preview').css({
width: Math.round(rx * 500) + 'px',
height: Math.round(ry * 370) + 'px',
marginLeft: '-' + Math.round(rx * coords.x) + 'px',
marginTop: '-' + Math.round(ry * coords.y) + 'px'
});
}
}
一张图片的工作示例在这里:
链接文本 http://deepliquid.com/projects/Jcrop/demos.php?demo=thumbnail
我想要的是向函数 showPreview(coords) 传递多个参数,例如:
function showPreview(coords,id,size_x,size_y)
{
if (parseInt(coords.w) > 0)
{
var rx = 100 / coords.w;
var ry = 100 / coords.h;
jQuery('#'+id).css({
width: Math.round(rx * size) + 'px',
height: Math.round(ry * size_y) + 'px',
marginLeft: '-' + Math.round(rx * coords.x) + 'px',
marginTop: '-' + Math.round(ry * coords.y) + 'px'
});
}
}
但出现错误。如何解决?