日期:2014-05-16  浏览次数:20404 次

如何用JS读出指定ID的DIV里抽值
<div   id= "a "> 111 </div>
<div   id= "b "> 222 </div>
<div   id= "c "> 333 </div>

我现在只想读出222的值,因为这个DIV的位置不确定,所以不能用.
alert(document.body.getElementsByTagName( "div ")[0].innerHTML)




------解决方案--------------------
document.getELementById( "b ").innerHTML
------解决方案--------------------
document.getElementById( "b ").innerHTML
------解决方案--------------------
直接b.innerHTML就好了......
------解决方案--------------------
<div id= "a "> 111 </div>
<div id= "b "> 222 </div>
<div id= "c "> <span> 333 <span> </div>
<input type= "button " value= "获取text的值 " onclick= "alert(document.getElementById( 'c ').innerText); " />
<input type= "button " value= "获取Html的值 " onclick= "alert(document.getElementById( 'c ').innerHTML); " />
------解决方案--------------------
document.getElementById( "b ").innerHTML
------解决方案--------------------
document.getElementById( "b ").innerHTML