如何利用JavaScript和HTML5編寫該題
qq_隨心依舊_0
2016-11-28 20:09:22
TA貢獻1036條經驗 獲得超461個贊
<!DOCTYPE?html>
<html?lang="en">
<head>
????<meta?charset="UTF-8">
????<meta?http-equiv="X-UA-Compatible"?content="IE=edge,chrome=1">
????<title>Title</title>
</head>
<body>
<input?id="input"?type=""/>
<select?name=""?id="select">
??<option?value="red">red</option>
??<option?value="blue">blue</option>
??<option?value="green">green</option>
</select>
<button?id="save">存儲</button>
<button?id="clear">清空</button>
<ol?id="list"></ol>
<script>
?var?input?=?document.getElementById('input');
?var?select?=?document.getElementById('select');
?var?list?=?document.getElementById('list');
?document.getElementById('save').onclick=function?()?{
?var?value?=?input.value;
?if(value?==?''){
?return;
????}
?var?li?=?document.createElement('li');
?li.innerHTML?=?value;
?li.style.color?=?select.value
?list.appendChild(li);
??}
?document.getElementById('clear').onclick?=?function?()?{
?list.innerHTML?=?'';
??}
</script>
</body>
</html>你是想要這個效果?
舉報