<HTML>
<BODY>
<Script>
String.prototype.format = function() {
var string = this;
var arg = arguments;
return string.replace(//{%(/d+)/}/g,
function(match, index) {
return arg[index-1];
});
}
function getMessage(messageID) {
var arg = Array.prototype.slice.call(arguments,1);
alert(arg);
var message;
message = "aa/{%1/}b/{%3/}b/{%2/}";
if(message == "") {
return message;
} else{
var argString = "";
for (var i=0; i<arg.length; i++) {
if (i == 0) {
argString += "/"" + arg[i] + "/"";
} else {
argString += "," + "/"" + arg[i] + "/"";
}
}
message = eval("message.format(" + argString + ");");
message = eval("message.format(" + argString + ");");
}
return message;
}
alert(getMessage(1, "ttt","ccc","EEE"));
</Script>
</BODY>
</HTML>
比较 getMessage
function getMessage(messageID,fukabungen1 ,fukabungen2 ,fukabungen3) {
var message;
message = "aa/{%1/}b/{%3/}b/{%2/}";
if(message == "") {
return message;
} else{
if (fukabungen1 != "") {
message = message.replace(new RegExp(//[%1/]/gm), fukabungen1);
}
if (fukabungen2 != "") {
message = message.replace(new RegExp(//[%2/]/gm), fukabungen2);
}
if (fukabungen3 != "") {
message = message.replace(new RegExp(//[%3/]/gm), fukabungen3);
}
}
return message;
}