Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.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
Javascript 如何在页面加载时弹出表单?_Javascript_Jquery_Html_Fancybox - Fatal编程技术网

Javascript 如何在页面加载时弹出表单?

Javascript 如何在页面加载时弹出表单?,javascript,jquery,html,fancybox,Javascript,Jquery,Html,Fancybox,我希望在某个页面上弹出一个登录表单 <a id="test" href="#login_form">Click me</a> <div style="display:none"> <form id="login_form" method="post" action="parse_login.php"> <p id="login_error">Please login<

我希望在某个页面上弹出一个登录表单

<a id="test" href="#login_form">Click me</a>

    <div style="display:none">
            <form id="login_form" method="post" action="parse_login.php">
                <p id="login_error">Please login</p>

            <table>
         <tr><td><input type='text' name='username' placeholder="username" style="width: 250px;" /><p /></tr></td>
                                <tr><td><input type='password' name='password' placeholder="password" style="width: 250px;" /><p /></tr></td>
                            </table>
                            <div class="logginbutton"><button type='submit' name='submit' class="button-small">Login</button>
                        </form>
                    </div>

请登录

登录

具体如下:

$("#test").fancybox({
    'scrolling'     : 'no',
    'titleShow'     : false,
    'onClosed'      : function() {
        $("#login_error").hide();
    }
});


$("#login_form").bind("submit", function() {

    if ($("#username").val().length < 1 || $("#password").val().length < 1) {
        $("#login_error").show();
        $.fancybox.resize();
        return false;
    }

    $.fancybox.showActivity();


    return false;
});
$(“#测试”).fancybox({
“滚动”:“否”,
“标题秀”:假,
“onClosed”:函数(){
$(“#登录错误”).hide();
}
});
$(“登录表单”).bind(“提交”,函数(){
if($(“#用户名”).val().length<1 | |$(“#密码”).val().length<1){
$(“#登录错误”).show();
$.fancybox.resize();
返回false;
}
$.fancybox.showActivity();
返回false;
});
我想要的是,表单应该在页面加载时弹出,而不是onclick,并且它应该保持在那里直到访问者登录,所以需要去掉关闭标志

试试看

jQuery(document).ready(function ($) {
    $.fancybox({
        href: "#login_form",
        modal: true,
        scrolling : 'no',
        titleShow: false,
        onClosed : function() {
            $("#login_error").hide();
        }
    });
});
它将在页面加载时启动fancybox

注意
模式:true
将阻止关闭fancybox,并且不会显示关闭按钮(退出或在框外单击也不会关闭)。如果在框内放置关闭按钮(绑定到
$.fancyblox.close()
方法),表单将关闭或者如果表单通过验证并提交

在这种情况下,您应该从此脚本中删除
returnfalse

$("#login_form").bind("submit", function() {  
    if ($("#username").val().length < 1 || $("#password").val().length < 1) {
        $("#login_error").show();
        $.fancybox.resize();
        return false; // prevents the form of being submitted if validation fails
    }    

    // $.fancybox.showActivity(); // you don't need this unless you are going to display the results in fancybox

    // return false; // <== this will prevent the form of being submitted, regardless it passes the validation
});
$(“登录表单”).bind(“提交”,函数(){
if($(“#用户名”).val().length<1 | |$(“#密码”).val().length<1){
$(“#登录错误”).show();
$.fancybox.resize();
return false;//防止在验证失败时提交表单
}    
//$.fancybox.showActivity();//除非要在fancybox中显示结果,否则不需要此选项

//return false;//当我点击你的
click me
时,一切都没有发生。因为他没有在“Frameworks&Extensions”中从左边选择jquery部分,然后fancybox js也没有加载。如何加载fancybox js?
外部资源
?添加
fancybox
js
CSS
文件的完整路径非常感谢。我真是太傻了,忘了编辑。它第一次在JSFIDLE上工作,然后它没有,可能是我的浏览器缓存了它,但是它在我的本地主机上工作。
<a id="test" href="#login_form">Click me</div>