<!DOCTYPE?html>
<html>
<head>
<meta?charset="utf-8">
<title>IFE?JavaScript?Task?01</title>
<style?type="text/css">
????p?span{
??????display:inline-block;
??????width:30px;
??????margin-left:10px;
??????background:?red;
????}
</style>
</head>
<body>
<input?type="text"?id="text">
<button?id="right-enter">點(diǎn)擊添加元素</button>
<p?id="aqi-display">
</p>
<script?type="text/javascript">
var?right_enter=document.getElementById('right-enter');
right_enter.addEventListener('click',function(){
var?mytext=document.getElementById('text');
var?myarea=document.getElementById('aqi-display');
var?i=document.createElement('span');
myarea.appendChild(i);
i.id='right-box';
var?j=document.getElementById('right-box');
j.style.height=mytext.value+'px';
})
</script>
</body>
</html>這里添加的元素可以不斷添加上,但是最后一步給添加style的height時(shí),一直只能賦給第一個(gè)元素,這怎么解決?謝謝指教
js添加元素
qq_一夢(mèng)兩三年丶_0
2017-05-04 18:20:55