javascript中的string.format
<script type="text/javascript">
String.prototype.format = function () {
var values = arguments;
return this.replace(/([^\{])?\{(\d+)\}(?!\})/g, function ($0, prefix, pos) {
//alert(pos);
pos = parseInt(pos);
return (prefix || "") + values[pos];
});
}
//使用方法
alert("name:{0}, sex:{1}".format("sss", "''(){'"));
alert("{0}, sex:{1}".format("sss", "''(){'"));
</script>
QQ:273352165
evlon#126.com
转载请注明出处。

浙公网安备 33010602011771号