2017-05-19 76 views
0

enter image description here 相同的腳本有2個不同的結果。當我寫4位數字。我得到這個錯誤。 哪裏可能是錯的。illustrator腳本,如果box1的值大於Box2,則發出警報

var win = new Window('dialog', "Example"); 

win.size = [280,200]; 

var columns = win.add("group"); columns.spacing=5; 

var width = columns.add('edittext {text: "", characters: 5, justify: "center"}'); 

var length = columns.add('edittext {text: "", characters: 5, justify: "center"}'); 

var height = columns.add('edittext {text: "", characters: 5, justify: "center"}'); 

width.active = true; 


var grp = win.add('group'); 

var ok = grp.add('button {text: "OK"}') 

grp.add('button {text: "Cancel"}'); 


var doBox = function(){ 

var box1=width.text; 

var box2=length.text; 

box1=width.text; 

box2=length.text; 

if (box1>box2) 

    alert("You have entered a big number in the 1st box !"); 

else 

    alert("Ok"); 

} 

ok.onClick = doBox; 

win.show(); 

回答

0

請參閱this answer,爲什麼發生這種情況。要糾正這個問題,你可以使用parseInt方法。要做到這一點只需要改變這些行

box1=width.text; 
box2=length.text; 

box1=parseInt(width.text); 
box2=parseInt(length.text); 
相關問題