我试图理解为什么它返回未定义。
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”属性。
关于JavaScript 客户端宽度 : why is this returning undefined?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21616338/