使用jQuery刷新div [英] Refresh a div with jQuery

查看:79
本文介绍了使用jQuery刷新div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用jQuery刷新单个div?我有一个注销用户的按钮。单击按钮后,我想显示登录表单,所以我需要重新解析这个div。

Is it possible to refresh a single div with jQuery? I have a button that does logout a user. After the button is clicked, I want to show the login form, so I need to re-parse this div.

我的div的内容是:

<div id="signup" class="register">

    <?php
        $email = $_COOKIE['email'];
        $login = $_COOKIE['login'];

        if($email != null && $email != "" && $login != null && $login != "") {
            echo "<h3>you are logged in as <b>$email</b></h3><br><br><button id='logoutbtn' class='submitButton'>Logout</button>";
        } else {
            // show login form
        }
    ?>

</div>

这是我执行注销的JavaScript部分:

This is my JavaScript part where I perform the logout:

$('#logoutbtn').click(function () {    
    $.ajax({  
        type: "POST",  
        url: "php/logout.php",  
        async: false,
        success: function(data){
            // reload signup div
        } 
    });  
});

编辑:我的logout.php脚本删除了cookie,这就是我需要重新解析注册的原因-div。

My logout.php script removes the cookies, that's why I need to re-parse the signup-div.

推荐答案

您可以使用jquery动态更改注册div的内容,如下所示:

You can dynamically change the contents of the signup div with jquery as follows:

$("#signup").html("My New Login Section");

var $loginDiv = $(document.createElement("div")).html("<label>Username</label><input type='text' id='username'/>");
$("#signup").html($loginDiv);

这篇关于使用jQuery刷新div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆