1. 程式人生 > >11月13日筆記心得

11月13日筆記心得

今天利用節點完成了在頁面上新增內容等東西,還可以有刪除方法和替換。然後經過自己思考和查資料做出來了。


<title>Coding Coffee</title>
<style>
#bian{
width: 800px;
height: 300px;
clear:both;
margin:0 auto;
}
.img{
float:left;
width: 50%;
margin:0 auto;
}
.p{
float:right;
width: 50%;
}


p,h1,h2{
text-align:center;
}
</style>
 </head>
<body>

<p>
咖啡名:<input id="name" type="text"  value="">
</p>
<p>
描述:<textarea id="description" type="text" cols="20" rows="10" ></textarea>
</p>
<p>
圖片地址:<input id="img_url" type="text" value="">
</p>
<button onclick="addCoffee()">新增咖啡</button>

<div id="bian">
<h1>Coding Coffee Menu</h1>
<div class="img">
<img src="../img/c2.jpg">
</div>
<div class="p">
<h2>藍山咖啡</h2>
<p>源自三地的咖啡豆,為週年紀念綜合咖啡豆帶來了特別的馥郁醇厚。如今推出三種不同包裝,讓你用自己喜愛的方式體驗這別具風味的一杯。</p>
</div>
<div style="clear: both;"></div>

</div>
<script type="text/javascript">
function addCoffee(){
var name=document.getElementById('name').value;
var desc=document.getElementById('description').value;
var img_url=document.getElementById('img_url').value;
var html1 ='<div class="bian"><div class="img"><img src="'+img_url+'"></div>';
var html2='<div class="p"><h2>'+name+'</h2><p>'+desc+'</p></div>';
var html3='<div style="clear: both;"></div></div>';
var add=html1+html2+html3;
var newhtml = document.getElementById('bian').innerHTML;
var newhtml2=add+newhtml;
document.getElementById('bian').innerHTML = newhtml2;

}

</script>
</body>