我很难调试它,因为它没有返回任何错误并且它在 ie9 中运行。我想知道是否存在某种常见问题导致脚本在 ie9 中运行但在 ie8 和 ie10 中不起作用。我觉得这个错误跳过一个版本很奇怪。
我的代码:
<script type="text/javascript">
jQuery(function($){
// Create variables (in this scope) to hold the API and image size
var jcrop_api,
boundx,
boundy,
// Grab some information about the preview pane
$preview = $('#preview-pane'),
$pcnt = $('#preview-pane .preview-container'),
$pimg = $('#preview-pane .preview-container img'),
xsize = $pcnt.width(),
ysize = $pcnt.height();
console.log('init',[xsize,ysize]);
$('#picture').Jcrop({
aspectRatio: <?php echo $_POST["aspectRatio"]; ?>,
setSelect: [ 0, 0, 300, 300 ],
onSelect: updateCoords
},function(){
// Use the API to get the real image size
var bounds = this.getBounds();
boundx = bounds[0];
boundy = bounds[1];
// Store the API in the jcrop_api variable
jcrop_api = this;
// Move the preview into the jcrop container for css positioning
$preview.appendTo(jcrop_api.ui.holder);
});
function updatePreview(c)
{
if (parseInt(c.w) > 0)
{
var rx = xsize / c.w;
var ry = ysize / c.h;
$pimg.css({
width: Math.round(rx * boundx) + 'px',
height: Math.round(ry * boundy) + 'px',
marginLeft: '-' + Math.round(rx * c.x) + 'px',
marginTop: '-' + Math.round(ry * c.y) + 'px'
});
}
};
function updateCoords(c)
{
$('#x').val(c.x / <?php echo $correctieCoordinates; ?>);
$('#y').val(c.y / <?php echo $correctieCoordinates; ?>);
$('#w').val(c.w / <?php echo $correctieCoordinates; ?>);
$('#h').val(c.h / <?php echo $correctieCoordinates; ?>);
};
function checkCoords()
{
if (parseInt($('#w').val())) return true;
alert('Please select a crop region then press submit.');
return false;
};
});
</script>
jcrop 函数没有在 ie8 和 ie10 中初始化。但在 ie9 和所有主要浏览器中都可以使用。