看板 million
作者 標題 [note] Android期中考上機考
時間 2013年05月18日 Sat. PM 04:59:53
為什麼javascript程式碼把list item (li) 放上去了以後, 馬上就消失了呢...
<html>
<head>
<title>Sites Without Servers</title>
<style>
body {
background: blue;
}
div#main {
background: green;
border: green 1px solid;
padding: 10%;
width: 50%;
-webkit-border-radius: 10px;
}
</style>
<mata charset="utf-8"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1.0"></meta>
<script language="javascript">
function addNewItem(){
var aaa = document.getElementById("foodName");
if(aaa.value == ""){
alert("required field: Food Name");
return false;
}
var myList = document.getElementById("foodList");
var newItem = document.createElement("li");
newItem.innerHTML = aaa.value;
myList.appendChild(newItem);
}
</script>
</head>
<body>
<div id="main">
<h1>期中考</h1>
<form id="foodForm">
<input type="text" id="foodName" placeholder="Food Name"/>
<button onclick="addNewItem()" id="submitFood">Tell Us!</button><br />
</form>
<ul id="foodList">
</ul>
</div>
</body>
</html>
--
※ 作者: emulators 時間: 2013-05-18 16:59:53
※ 看板: million 文章推薦值: 0 目前人氣: 0 累積人氣: 186
1樓 時間: 2013-05-18 17:03:40 (台灣)
→
05-18 17:03 TW
我成功了...把<button></button>改成<input type=button />就好了
回列表(←)
分享