2009-11-24 53 views
0

嗨有人知道为什么这只是不会工作!我曾尝试alsorts。parseInt,parseFloat,Number ...我不知道

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 

它的工作原理

任何想法?

+0

摆脱的jQuery(函数(widthN,heightN){'和相关收盘'})的',' – 2009-11-24 17:54:24

+0

HAHAHAHHAHAHA好男人! – 2009-11-24 18:03:04

回答

1

首先,我会在一个点进行计算。其次,我认为你比Math.round更好。然而,最重要的是,你在内部函数中使用函数参数,我不认为你想这样做(它将取消设置变量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) 
       });  
     }); 
    } 
} 
+0

的作品是一样的,但我看到你来自哪里...有一个小问题,但我想我没有办法做到这一点。不知道你是否曾经使用jCrop,但你可以设置纵横比。使用所写的一切,实际的方面略微。但我认为这可能是由于jCrop编码。谢谢。 – 2009-11-24 18:54:33

相关问题