使用函数调用调用Colorbox,但它一打开就会关闭

时间:2012-11-12 15:36:09

标签: javascript html iframe javascript-events colorbox

我正在做的是调用一个函数passval(),它本身正在调用另一个显示colorbox iframe的函数menu()

<html>
<head>
<link rel="stylesheet" href="colorbox/colorbox.css" />
<script src="js/jquery.min.js"></script>
<script src="colorbox/jquery.colorbox.js"></script>
<script>
            $(document).ready(function(){
                //Examples of how to assign the ColorBox event to elements

                $(".group3").colorbox({rel:'group3', transition:"none", width:"75%", height:"75%"});
                $(".inline").colorbox({inline:true, width:"40%"});
                $(".iframe").colorbox({iframe:true, width:"90%", height:"80%"});

            });
            </script>


    <script type="text/javascript">
    function passval()
    {

    var vc = document.getElementById('vc').value;
    var fc = document.getElementById('fc').value;
    //checking inputs
    //document.write(fc+" ");
    //document.write(vc+" ");
    //document.getElementById('inline').click();
    menu();
    }
    function menu() 
    {
      $('<a />').colorbox({fixedWidth:"500px", fixedHeight:"300px", iframe:true, href:"search.php", bgOpacity:0, open:true}); return false;
     }

    </head>
    <body>
    <form id="form1" name="form1" method="post">
    <input type="submit" value="Submit" onclick="passval()" />
    </form>
    <a class='iframe' id="inline" href="chart.htm">iFrame</a>
    </body>
    </html>

但是它一打开就会打开和关闭..同样是单击函数调用的[document.getElementById('inline').click();]

有任何建议吗?

1 个答案:

答案 0 :(得分:0)

点击提交时需要preventDefault()。现在您的页面已重新加载或更改:

<input type="button" value="Submit" onclick="passval()" />