我有代碼,想找到的第一個孩子(DIV)一個div的和不是改變它的內容,這裏是我的代碼:更改文本
var headDiv = document.getElementById('sliderContainer');
var childDiv = headDiv.childNodes[0];
childDiv.innerHTML = 'Working';
,似乎不工作,有什麼問題在這裏?
生活:http://jsbin.com/aqozef/edit#javascript,html,live
的完整代碼:
<!doctype html>
<html>
<head>
<script type="javascript">
function scrollit(){
var headDiv = document.getElementById('sliderContainer');
var childDiv = headDiv.childNodes[0];
childDiv.innerHTML = 'Working';
}
</script>
<style type="text/css">
#sliderContainer{width:100px;height:100px;overflow:hidden;}
.sliderContent{width:100px;height:100px;float:left;}
</style>
</head>
<body>
<div id="sliderContainer">
<div class="sliderContent" style="background-color:blue;">s</div>
<div class="sliderContent" style="background-color:yellow;">a</div>
</div><br/><br/>
<button onclick="scrollit();">scroll it</button>
</body>
</html>
請張貼HTML內容以及 – Saket