illustrator脚本,如果box1的值大于Box2,给出alert
illustrator script, If the value of box1 is greater than Box2, give alert
同一个脚本有 2 个不同的结果。当我写 4 位数字时。我收到这个错误。
哪里可能不对。
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();
请参阅this answer, for why this happens. to correct this problem you can use parseInt方法。为此,只需更改这些行
box1=width.text;
box2=length.text;
至
box1=parseInt(width.text);
box2=parseInt(length.text);
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();
请参阅this answer, for why this happens. to correct this problem you can use parseInt方法。为此,只需更改这些行
box1=width.text;
box2=length.text;
至
box1=parseInt(width.text);
box2=parseInt(length.text);