Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        5年前关闭。
                                                                                            
                
        
我试图理解为什么这返回未定义。

function showMarquee(marquee_string) {
    $('#text-helper').html(marquee_string);
    var test = document.getElementById("text-helper").innerHTML;
    var width = (test.clientWidth); //why isn't this line working?
    alert(width);  //this returns undefined
}
showMarquee('Silver Linings Playbook');


HTML如下:

<div class="currentwatchtext" id="currentwatchtext">
    <div id="marquee-screen"></div>
    <div id="text-helper"></div>
</div>


CSS是:

#text-helper{
    position: absolute;
    visibility: hidden;
    height: auto;
    width: auto;
}


对此事的任何投入表示赞赏。

最佳答案

.innerHTML属性的值是一个字符串,并且字符串没有“ clientWidth”属性。

10-01 04:00
查看更多