This not works and I can't figure it out why...
alert("milan {0}".format("djukic"));
My jquery
version is 1.6.2.
I tried everything and no success..
This not works and I can't figure it out why...
alert("milan {0}".format("djukic"));
My jquery
version is 1.6.2.
I tried everything and no success..
This isn't an error related to jQuery - it's the fact that you're trying to run a string instance's method that doesn't exist. A quick search gives me another StackOverflow answer, which happily implements String#format
for you.
String.prototype.format = function() {
var str = this;
for (var i = 0; i < arguments.length; i++) {
var reg = new RegExp("\\{" + i + "\\}", "gm");
str = str.replace(reg, arguments[i]);
}
return str;
}
Just paste that at the top or near to the top of your script file and use your newly-created function like "the {0} jumps over the {1}".format("quick brown fox", "lazy dog");
in the script.