我有代码,想找到的第一个孩子(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