gpt4 book ai didi

JavaScript 循环语法

转载 作者:行者123 更新时间:2023-11-28 16:31:10 24 4
gpt4 key购买 nike

这对某人来说应该很容易,我只是似乎无法正确理解语法。我有以下代码,我确信其中 70% 可以用循环表示:有人可以启发我吗?

function AddNewEmail(){
var jFilesContainer = $( "#emails" );
var jUploadTemplate = $( "#email-templates div.template" );
var jUpload = jUploadTemplate.clone();
var strNewHTML = jUpload.html();
var intNewFileCount = (jFilesContainer.find( "div.template" ).length + 1);
jUpload.attr( "id", ("emailedit[" + intNewFileCount + "]") );
strNewHTML = strNewHTML
.replace(
new RegExp( "::FIELD1::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD2::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD3::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD4::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD5::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD6::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD7::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD8::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD9::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD10::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD11::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD12::", "i" ),
intNewFileCount
)

;

jUpload.html( strNewHTML );
jFilesContainer.append( jUpload );
}

最佳答案

如果您使用正则表达式,请使用它们:

strNewHTML = strNewHTML.replace(/::FIELD\d{1,2}::/gi, intNewFileCount);

关于JavaScript 循环语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5934889/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com