我有一个引导模式,其编号为myModal
。clientWidth的自举模态返回0
在我的javascript当我这样做
window.onload = function(){
var container = document.getElementById("myModal");
console.log(container.clientWidth);
}
它显示0
。 如何在Bootstrap模式打开之前获取clientWidth?
我有一个引导模式,其编号为myModal
。clientWidth的自举模态返回0
在我的javascript当我这样做
window.onload = function(){
var container = document.getElementById("myModal");
console.log(container.clientWidth);
}
它显示0
。 如何在Bootstrap模式打开之前获取clientWidth?
jQuery的width
工作得很好
$('#ModalName').find('.modal-dialog').width()
对于$('#ModalName')
你总是得到错误的值。
那么你知道些什么。 jQuery的作品。但任何想法为什么纯JS客户端的宽度不工作? –
在[这篇文章](http://stackoverflow.com/questions/294250/how-do-i-retrieve-an-html-elements-actual-width-and-height)有关于评论中同样的问题的讨论为接受答案。也许它对你有用。 – user3272018
更多详细信息[here](http://stackoverflow.com/questions/1841124/find-the-potential-width-of-a-hidden-element)和[here](http://stackoverflow.com/questions/ 30637577 /如何对获得-clientwidth-clientheight前方的DIV-是可见的)。 – user3272018
你能分享可执行的演示/片段或[JSFiddle](https://jsfiddle.net/)吗? [_创建一个最小,完整和可验证的示例_](http://stackoverflow.com/help/mcve) – Rayon