StringFormat

<!DOCTYPE HTML>
<html lang="en">
<head>
	<meta charset="GB2312">
	<title>strFormat</title>
</head>
<body>
    <script type="text/javascript">
		
		String.prototype.formatTemp = function(){
			var s = this;
            for (var i = 0, j = arguments.length; i < j; i++){ 
				s = s.replace("{" + (i) + "}", arguments[i]);
            }
			return (s);
		}

        var Data = [
            {
                name: "zzyifan", 
                mail: "[email protected]", 
                weibo: "http://t.qq.com/zzyvon"
            },
            {
                name: "vimerlu", 
                mail: "[email protected]", 
                weibo: "http://weibo.com/vimerlu"
            }
        ];
        var html = "<ul>";
        var temp = '<li class="item"><a href="{2}">{0}</a>&nbsp;<span>{1}</span>';
        for(var i = 0, len = Data.length; i < len; i++){
            var d = Data[i];
            html += temp.formatTemp(d.name, d.mail, d.weibo);
        }
        html += "</ul>";
        document.write(html);


    
    </script>
	
</body>
</html>
 

你可能感兴趣的:(String)