Modal Dialog without jQuery(没有 jQuery 的模态对话框)
问题描述
我需要使用 javascript 在网页上创建模式对话框.通常这很容易,因为我可以使用 jQueryUI 或 BlockUI 之类的东西,但需要注意的是,我不允许使用 jQuery,并且我需要支持 IE9 怪癖模式(即没有 html5 doctype).我在网上找不到任何与我需要的东西有关的东西.有人会有建议吗?谢谢.
用中间居中的div做overlay怎么样?
您可以拥有可以隐藏的 div(使用 javascript):
<div id="overlay"><p>你想让用户看到的内容放在这里.</p></div></div>叠加层的 CSS 样式如下所示:
#overlay {可见性:隐藏;位置:绝对;左:0px;顶部:0px;宽度:100%;高度:100%;文本对齐:居中;z 指数:1000;}
然后就可以用JavaScript来切换overaly div中内容的可见性了:
函数覆盖(){el = document.getElementById("overlay");el.style.visibility = (el.style.visibility == "visible") ?隐藏":可见";}
更多示例:http://raventools.com/blog/create-a-modal-dialog-using-css-and-javascript/
I need to create a modal dialog on a webpage using javascript. Normally this would be easy as I could use something like jQueryUI or BlockUI, but the caveat here is that I'm not permitted to use jQuery, and I need to support IE9 quirks mode (ie no html5 doctype). I can't find anything online pertaining to what I need. Would anyone have suggestions? Thanks.
解决方案 What about doing overlay with a div centered in the middle?
You can have div which you can hide (using javascript):
<div id="overlay">
<div>
<p>Content you want the user to see goes here.</p>
</div>
</div>
The CSS style for overlay can look like this:
#overlay {
visibility: hidden;
position: absolute;
left: 0px;
top: 0px;
width:100%;
height:100%;
text-align:center;
z-index: 1000;
}
Then you can use JavaScript to switch the visibility of the content in the overaly div:
function overlay() {
el = document.getElementById("overlay");
el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
}
More for example here: http://raventools.com/blog/create-a-modal-dialog-using-css-and-javascript/
这篇关于没有 jQuery 的模态对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:没有 jQuery 的模态对话框


- Flexslider 箭头未正确显示 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01