简单javascript循环
这是illustrator的extendscript,但基本上是javascript。我希望第二个弹出窗口只显示一次,我试图告诉它变量是否已经存在,但如果不存在,则请求输入。知道我做错了什么吗简单javascript循环,javascript,loops,input,extendscript,Javascript,Loops,Input,Extendscript,这是illustrator的extendscript,但基本上是javascript。我希望第二个弹出窗口只显示一次,我试图告诉它变量是否已经存在,但如果不存在,则请求输入。知道我做错了什么吗 #target illustrator if ( app.documents.length > 0 ) { var replaceThis = prompt('What font do you want to replace?','') for ( i = 0; i< app.
#target illustrator
if ( app.documents.length > 0 ) {
var replaceThis = prompt('What font do you want to replace?','')
for ( i = 0; i< app.activeDocument.textFrames.length; i++) { //loop through the layers
var textArtRange = app.activeDocument.textFrames[i].textRange;
var fontSize = textArtRange.characterAttributes.size;
//var replaceThis = "10";
//alert("replace this:" + replaceThis);
// alert("current font size" + fontSize);
if (fontSize == replaceThis) {
Replacefont();
}
function Replacefont () {
//var newSize = "90";
if (!newSize) {
var newSize = prompt('Replace '+ replaceThis +'pt with:','')
}
textArtRange.characterAttributes.size = newSize;
alert("yay");
}
}
}
#目标illustrator
如果(app.documents.length>0){
var replaceThis=prompt('要替换什么字体?','')
对于(i=0;i
newSize
仅在ReplaceFont
中可用,并且每次函数结束时都会被丢弃。您需要像这样使其持久化(没有真正的理由创建单独的函数)。也不要忘记for
循环的var
#target illustrator
if ( app.documents.length > 0 ) {
var replaceThis = prompt('What font do you want to replace?','');
var newSize = prompt('Replace '+ replaceThis +'pt with:','');
for ( var i = 0; i < app.activeDocument.textFrames.length; i++) {
var textArtRange = app.activeDocument.textFrames[i].textRange;
var fontSize = textArtRange.characterAttributes.size;
if (fontSize == replaceThis) {
textArtRange.characterAttributes.size = newSize;
alert("yay");
}
}
}
#目标illustrator
如果(app.documents.length>0){
var replaceThis=prompt('要替换什么字体?','');
var newSize=prompt('Replace'+replaceThis+'pt为:','');
对于(var i=0;i