我具有功能,当您将“值和高度”设置为“相同高度和宽度”时,当将某些值传递到其中时,var constrainsProportions
启用从高度grpHeight.numb
到宽度grpWidth.numb
的对应值,反之亦然分别在grpWidth.numb.onChange = function()
和grpHeight.numb.onChange = function()
中调用。
而且有效。
同样,当您选中该复选框时,它将采用最高值并将其传递给第二个。
在条件if (constrainsProportions.value == true)
中调用
而且也可以。
错误是在传递任何edittext
中的值时(您未按Enter或退出编辑)时,单击复选框。它再次取最高值并将其传递给第二个。
它不应该工作。任何值都不应更改。
即使当constrainsProportions.value
是false
时,您再次单击复选框。并且在这种情况下,不应调用grpWidth.numb.onChange()
else grpHeight.numb.onChange
不知道哪里出错了。
码
#target photoshop
var mainWindow = new Window("dialog", "dynamic changing values");
var grpUnitVal = mainWindow.add("group")
var constrainsProportions = grpUnitVal.add("checkbox", undefined, "Same Height and Width");
//Edittext: Height
var grpHeight = mainWindow.add("group")
grpHeight.text = grpHeight.add("statictext", undefined, "Height: ");
grpHeight.numb = grpHeight.add("edittext", undefined, 0);
grpHeight.numb.characters = 9;
//Edittext: Width
var grpWidth = mainWindow.add("group")
grpWidth.text = grpWidth.add("statictext", undefined, "Width: ");
grpWidth.numb = grpWidth.add("edittext", undefined, 0);
grpWidth.numb.characters = 9;
//Edittext: Width; if "constrains proportion" is checked, Heigth and Width values are changed in the same time
grpWidth.numb.onChange = function() {
if (constrainsProportions.value == true){
grpHeight.numb.text = grpWidth.numb.text;}
}
//Edittext: Height; if "constrains proportion" is checked, Heigth and Width values are changed in the same time
grpHeight.numb.onChange = function() {
if (constrainsProportions.value == true){
grpWidth.numb.text = grpHeight.numb.text;}
}
constrainsProportions.onClick = function() {
//Set the same heighest value in Height and Width
alert(constrainsProportions.value);
if (constrainsProportions.value == true){
if (parseInt(grpWidth.numb.text, 10) > parseInt(grpHeight.numb.text, 10)) {
grpWidth.numb.onChange();}
else {
grpHeight.numb.onChange();}
}
}
mainWindow.show();
提前致谢。
最佳答案
发生这种情况是因为onChange()
事件是在控件失去焦点时发送的,而不是在您键入时发送的,因此代码获得了在面板上看到的内容的先前版本。使用onChanging
代替:
#target photoshop
var mainWindow = new Window("dialog", "dynamic changing values");
var grpUnitVal = mainWindow.add("group")
var constrainsProportions = grpUnitVal.add("checkbox", undefined, "Same Height and Width");
//Edittext: Height
var grpHeight = mainWindow.add("group")
grpHeight.text = grpHeight.add("statictext", undefined, "Height: ");
grpHeight.numb = grpHeight.add("edittext", undefined, 0);
grpHeight.numb.characters = 9;
//Edittext: Width
var grpWidth = mainWindow.add("group")
grpWidth.text = grpWidth.add("statictext", undefined, "Width: ");
grpWidth.numb = grpWidth.add("edittext", undefined, 0);
grpWidth.numb.characters = 9;
//Edittext: Width; if "constrains proportion" is checked, Heigth and Width values are changed in the same time
grpWidth.numb.onChanging = function() {
if (constrainsProportions.value){
grpHeight.numb.text = this.text;}
}
//Edittext: Height; if "constrains proportion" is checked, Heigth and Width values are changed in the same time
grpHeight.numb.onChanging = function() {
if (constrainsProportions.value){
grpWidth.numb.text = this.text;}
}
constrainsProportions.onClick = function() {
//Set the same heighest value in Height and Width
// alert(constrainsProportions.value);
if (this.value){
if (parseInt(grpWidth.numb.text, 10) > parseInt(grpHeight.numb.text, 10)) {
grpHeight.numb.text = grpWidth.numb.text;}
else {
grpWidth.numb.text = grpHeight.numb.text;}
}
}
mainWindow.show();
关于javascript - 执行“如果陈述”结果,但不应该执行。取消选中复选框时激活功能-脚本CS6 64位Photoshop,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59325231/