Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 页面加载时打开显示模型不工作_Jquery_Css_Html - Fatal编程技术网

Jquery 页面加载时打开显示模型不工作

Jquery 页面加载时打开显示模型不工作,jquery,css,html,Jquery,Css,Html,我正在使用Jquery模式,它可以在href单击时轻松打开 并显示弹出窗口。 我的html页面是 <!DOCTYPE html> <head> <meta charset="utf-8" /> <title>Reveal Demo</title> <link rel="stylesheet" href="reveal.css"> <sc

我正在使用Jquery模式,它可以在href单击时轻松打开 并显示弹出窗口。
我的html页面是

<!DOCTYPE html>

    <head>
        <meta charset="utf-8" />
        <title>Reveal Demo</title>

        <link rel="stylesheet" href="reveal.css">   

        <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script>
        <script type="text/javascript" src="jquery.reveal.js"></script>

        <style type="text/css">
            body { font-family: "HelveticaNeue","Helvetica-Neue", "Helvetica", "Arial", sans-serif; }
            .big-link { display:block; margin-top: 100px; text-align: center; font-size: 70px; color: #06f; }
        </style>
            <script type="text/javascript">

                $(document).ready(function() {
                    $('a[data-reveal-id]').live( 'click',function(e) {
                        e.preventDefault();
                        var modalLocation = $(this).attr('data-reveal-id');
                        $('#'+modalLocation).reveal($(this).data());
                });
            });
        </script>

    </head>
    <body>

        <a href="#" data-reveal-id="myModal">
            Fade and Pop
        </a>    

        <div id="myModal" class="reveal-modal">
            <h1>Reveal Modal Goodness</h1>
            <p>This is a default modal in all its glory, but any of the styles here can easily be changed in the CSS.</p>
            <a class="close-reveal-modal">&#215;</a>
        </div>

    </body>
</html>

展示演示
正文{字体系列:“HelveticaNeue”、“Helvetica Neue”、“Helvetica”、“Arial”,无衬线;}
.big链接{显示:块;页边距顶部:100px;文本对齐:中心;字体大小:70px;颜色:#06f;}
$(文档).ready(函数(){
$('a[数据显示id]')。实时('click',函数(e){
e、 预防默认值();
var modalLocation=$(this.attr('data-discover-id');
$('#'+modalLocation).discover($(this.data());
});
});
显示模态善
这是一个默认模式,但这里的任何样式都可以在CSS中轻松更改

×
我的输出是

<!DOCTYPE html>

    <head>
        <meta charset="utf-8" />
        <title>Reveal Demo</title>

        <link rel="stylesheet" href="reveal.css">   

        <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script>
        <script type="text/javascript" src="jquery.reveal.js"></script>

        <style type="text/css">
            body { font-family: "HelveticaNeue","Helvetica-Neue", "Helvetica", "Arial", sans-serif; }
            .big-link { display:block; margin-top: 100px; text-align: center; font-size: 70px; color: #06f; }
        </style>
            <script type="text/javascript">

                $(document).ready(function() {
                    $('a[data-reveal-id]').live( 'click',function(e) {
                        e.preventDefault();
                        var modalLocation = $(this).attr('data-reveal-id');
                        $('#'+modalLocation).reveal($(this).data());
                });
            });
        </script>

    </head>
    <body>

        <a href="#" data-reveal-id="myModal">
            Fade and Pop
        </a>    

        <div id="myModal" class="reveal-modal">
            <h1>Reveal Modal Goodness</h1>
            <p>This is a default modal in all its glory, but any of the styles here can easily be changed in the CSS.</p>
            <a class="close-reveal-modal">&#215;</a>
        </div>

    </body>
</html>

正如你所看到的,点击“淡入淡出”链接,弹出窗口就会打开

但是我想在页面加载时打开这个弹出窗口。我试了很多,但是
我没有得到结果。我出错的地方。

您正在
中调用discover a
click事件,在
文档中调用它。ready
应该可以工作

在document.ready函数中尝试

$(document).ready(function() {  //or  $(window).load(function(){ 
    $('#myModal').reveal($(this).data());
});

您需要确保在点击链接弹出窗口时和页面加载时都会发生。因此,您所能做的就是添加
。在结束时单击()
,如下所示,看看这是否适合您

$(document).ready(function() {
   $('a[data-reveal-id]').live( 'click',function(e) {
       e.preventDefault();
       var modalLocation = $(this).attr('data-reveal-id');
       $('#'+modalLocation).reveal($(this).data());
   }).click();
});//-^^^^^^^----------------add this

我试过了,但不起作用。你也经历过同样的问题吗?没有,但这应该行得通。。。你有什么错误吗?检查你的控制台控制台。。。很高兴这有帮助。。。干杯快乐的朋友……)上面的代码可以工作,但您需要更改.live with.on和remove.click()(对于最新版本的jquery)