简单的模态和Javascript调用

时间:2012-07-11 07:47:59

标签: javascript jquery

我创建了一个简单模态弹出对话框,如果单击

,它就可以正常工作
    <a href='#' class='confirm'>Demo</a>

但是如何在Javascript中调用这个“confirm”css类。我试过......

    <script language="JavaScript" type="text/JavaScript">
       $(".confirm").click();
       ** Also tried this to but no good... **
       document.getElementsByTagName('body')[0].className = 'confirm';
    </script>

但没有奏效。我确信这很容易做到,但似乎无法得到它。

谢谢,

Frank G。

** * 这是我使用的脚本 * ** * ** * ****                                      SimpleModal确认模态对话框                  

    <!-- Page styles -->
    <link type='text/css' href='css/demo.css' rel='stylesheet' media='screen' />

    <!-- Confirm CSS files -->
    <link type='text/css' href='css/confirm.css' rel='stylesheet' media='screen' />


    <!-- JS files are loaded at the bottom of the page -->
    </head>
    <body>
    <div id='container'>
<div id='logo'>
    <h1>Simple<span>Modal</span></h1>
    <span class='title'>A Modal Dialog Framework Plugin for jQuery</span>
</div>
<div id='content'>
    <div id='confirm-dialog'>
        <h3>Confirm Override</h3>
        <p>A modal dialog override of the JavaScript confirm function. Demonstrates the use of the <code>onShow</code> callback as well as how to display a modal dialog confirmation instead of the default JavaScript confirm dialog.</p>
        <input type='button' name='confirm' class='confirm' value='Demo'/> or <a href='#' class='confirm'>Demo</a>
    </div>

    <!-- modal content -->
    <div id='confirm'>
        <div class='header'><span>Confirm 123</span></div>
        <div class='message'></div>
        <div class='buttons'>
            <div class='no simplemodal-close'>No</div><div class='yes'>Yes</div>
        </div>
    </div>
    <!-- preload the images -->
    <div style='display:none'>
        <img src='img/confirm/header.gif' alt='' />
        <img src='img/confirm/button.gif' alt='' />
    </div>
</div>
    </div>


    <!-- Load JavaScript files -->
    <script type='text/javascript' src='js/jquery.js'></script>
    <script type='text/javascript' src='js/jquery.simplemodal.js'></script>
    <script type='text/javascript' src='js/confirm.js'></script>

    <script type="text/javascript">
  $('.confirm').dialog({modal:true});
      $('.confirm').modal();
  $(".confirm").click();

    $(document).ready(function(){
   $('.confirm').dialog({modal:true});
       $('.confirm').modal();
   $(".confirm").click();
     });​

    </script>

    </body>
    </html>

2 个答案:

答案 0 :(得分:0)

也许你可以试试这个jquery解决方案:

$("style[type=text/css]").text('@import url("*.css");');

答案 1 :(得分:0)

要在页面加载时调用它,只需在文档就绪中调用它

$(document).ready(function(){
    $('#modal_div_id').modal(); // Id would be better (#confirm)
});​

这将在页面加载时调用它。确保您在名为class的页面中只有一个confirm

Documentation.

A fiddle here