js写面对对象 内部对象不能使用getElementById?该怎么处理
js写面对对象 内部对象不能使用getElementById?
<div id="div1">
<div id="div2"></div>
</div>
<script>
new a();
function a(){
this.d1=document.getElementById('div1');
this.d2=this.d1.getElementById('div2');//Uncaught TypeError: Object #<HTMLDivElement> has no method 'getElementById'
alert(this.d2);
}
</script>
请问为什么
?
谢谢
------解决思路----------------------
....不就相当于这样写吗? document.getElementById("div1").getElementById("div2")
不同于getElementsByTagName, getElementById只有document能调
与面向对象, this什么的无关
<div id="div1">
<div id="div2"></div>
</div>
<script>
new a();
function a(){
this.d1=document.getElementById('div1');
this.d2=this.d1.getElementById('div2');//Uncaught TypeError: Object #<HTMLDivElement> has no method 'getElementById'
alert(this.d2);
}
</script>
请问为什么
?
谢谢
------解决思路----------------------
....不就相当于这样写吗? document.getElementById("div1").getElementById("div2")
不同于getElementsByTagName, getElementById只有document能调
与面向对象, this什么的无关