【发布时间】:2011-05-09 09:22:37
【问题描述】:
这对某人来说应该很容易,但我似乎无法正确使用语法。我有以下代码,我确信其中 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 );
}
【问题讨论】:
-
什么不行,有什么问题?
标签: javascript loops syntax for-loop