JQuery小練習:畫出一個三角形

一、HTML源碼

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script charset="utf-8" src="jquery.js"></script>
<script type="text/javascript">
	$(function(){
	var dom = null;
	var arr = null;
	var _=function(){
		this.dom = document;
		this.arr = new Array();
	}
	_.prototype.createEle = function(id){
		var div = this.dom.createElement("DIV");
		div.id=id;
		div.style.textAlign="center";
		return div;
		}
	_.prototype.showText=function(id,length){
		var node = this.createEle(id);
		this.dom.body.appendChild(node);
		//alert(this.dom.getElementById("text").getAttribute("id"));
		for(var i=0;i<length;i++){
			if(i==0){
				this.arr.push("*");
			}
			this.arr.push(this.arr[i]+"*");
		}
		for(var m=0;m<this.arr.length;m++){
			this.dom.getElementById(id).innerHTML += this.arr[m]+"<br />";
		}	
	}	
		window.$Fuck = new _();	
		$Fuck.showText("text",15);//三角形層數爲16層
	});
</script>
</head>
<body>

</body>
</html>

二、執行結果

相關文章
相關標籤/搜索