我需要更新 x 和 y 值以通过 Ajax 和 PHP 裁剪图像。
此代码在单击按钮时打开一个带有图像的对话框窗口。工作正常,但 Firebug 显示 NaN 后变量。我怎样才能得到正确的值?我试过 parseFloat() 和 parseInt() 来返回一个数字变量。
jQuery(function($) {
jQuery('#jc-hidden-image').Jcrop({
onChange: showCoords,
onSelect: showCoords
});
});
function showCoords(c) {
jQuery('#x1').val(c.x);
jQuery('#y1').val(c.y);
jQuery('#x2').val(c.x2);
jQuery('#y2').val(c.y2);
jQuery('#w').val(c.w);
jQuery('#h').val(c.h);
};
jQuery(function($) {
$('#jc-dyn-btn').click(function() {
var jcrop_api;
var id = $(this).attr('data-id');
var rel = $(this).attr('data-rel');
var value = $(this).attr('data-value');
var mainImage = rel + '/' + id;
var x, y, w, h;
x = Math.round($('#x1').val());
y = Math.round($('#y1').val());
w = Math.round($('#w').val());
h = Math.round($('#h').val()); …Run Code Online (Sandbox Code Playgroud)