close
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<ol>
<li>aa</li>
<li>bb</li>
<li>cc</li>
<li>dd</li>
<li>ee</li>
</ol>
<input type="number" id="number" min='0' max="5">
<button id="btn">按我插進去這個數字之前</button>
<script type="text/javascript">
document.getElementById('btn').onclick=function(){
var number=document.getElementById('number').value;
number=parseInt(number);
var createElement=document.createElement('li');
createElement.appendChild(document.createTextNode('呵呵'));
var nowgoto=document.getElementsByTagName('li').item(number-1);
document.getElementsByTagName('ol')[0].insertBefore(createElement,nowgoto);
}
</script>
</body>
</html>
全站熱搜
留言列表