1 回答
李晓健
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>
你是想要这个效果?
添加回答
举报
0/150
提交
取消