Javascript parseInt,parseFloat,Number。。。我不知道

Javascript parseInt,parseFloat,Number。。。我不知道,javascript,Javascript,嗨,有人知道为什么这样不行吗!!我试过运动 function loadJcrop(widthN, heightN){ var run = true; if( run === true ) { alert( parseInt(Number(widthN) / Number(heightN)) ); jQuery(function(widthN, heightN) { jQuery('#cropbox').Jcrop({

嗨,有人知道为什么这样不行吗!!我试过运动

function loadJcrop(widthN, heightN){
    var run = true;
    if( run === true ) {
        alert(  parseInt(Number(widthN) / Number(heightN)) );
        jQuery(function(widthN, heightN) {
            jQuery('#cropbox').Jcrop({
                onChange: showCoords, onSelect: showCoords, aspectRatio: parseInt(Number(widthN) / Number(heightN))
              });       
        });
    }
}

jQuery(window).load(function() {
    loadJcrop(16, 1);
});
警报返回16,但什么也没有

如果我把

aspectRatio: 16
它起作用了


有什么想法吗???

首先,我会在一个点上进行计算。第二,我认为你最好学数学。然而,最重要的是,您正在内部函数中使用函数参数,我认为您不想这样做(这将取消设置变量heightN和widthN)

我将把该函数重新编写为:

function loadJcrop(widthN, heightN){
    // This is much clearer and easier to understand.
    var current = Math.round( Number(widthN) / Number(heightN) );
    var run = true;
    if( run ) { // if you have a variable which is a Boolean, 
                // you should not use '=='
        alert(  current );
        jQuery(function(/* Note the empty parameters */) {
                jQuery('#cropbox').Jcrop({
                        onChange: showCoords, onSelect: showCoords, aspectRatio: current)
              });       
        });
    }
}

去掉
jQuery(函数(widthN,heightN){
和相关的关闭
})哈哈哈哈哈,好人!!工作原理相同,但我知道你来自哪里。。。有点小问题,但我想我对此无能为力。不知道您是否使用过jCrop,但您可以设置纵横比。从我写的所有东西来看,实际的方面有点不对劲。但我认为这可能是由于jCrop编码。谢谢