如何获得bootstrap模态大小 [英] How to get bootstrap modal size
问题描述
我有一个bootstrap模式,其大小设置为:
I have a bootstrap modal whose size is set by:
<div class="modal-dialog modal-lg">
我希望能够在发出帖子请求之前确定模态的大小(实际宽度)一个PHP程序,用于在显示模态之前显示一些动态内容。有谁知道如何获取这些信息?
I want to be able to determine the modal's size (width actually) before I make a post request to a PHP program to display some dynamic content before displaying the modal. Does anyone know how to get this information?
推荐答案
如果你想要使用Javascript的元素的实际尺寸,JQuery有内置在 .width()
和 .height()
函数中。我修改了您的< div>
以添加一个数据 -
属性,该属性包含您想要访问的引导类和一个便于访问的ID:
If you want the actual dimensions of an element using Javascript, JQuery has the built in .width()
and .height()
functions. I modified your <div>
to add a data-
attribute that has the bootstrap class incase you want to access that and an ID for easier access:
<div id="my_modal" class="modal-dialog modal-lg" data-size="modal-lg">
然后通过Javascript访问它:
Then access it via Javascript:
var width = $("#my_modal").width();
var height = $("#my_modal").height();
var size = $("#my_modal").attr("data-size");
console.log("Width Is: " + width + " and Height Is:" + height + "and Size Is:" + size);
希望有所帮助!
这篇关于如何获得bootstrap模态大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!