php简单弹窗

这里采用layer弹层组件

layer弹层组件

/**
  * 弹窗
  * addtime 2020年9月4日 09:55:03
  * author Turbo
  * @param string $msg 提示消息
  * @param string $url 跳转链接
  * @return void
  */
function show_msg($msg="", $url="")
{
   
    @header(
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以通过以下步骤实现一个基于PHP的登录注册JS弹窗: 1. 创建一个登录注册页面,包括表单和对应的处理PHP代码。 2. 在登录注册页面中添加一个JavaScript函数,用于显示弹窗。 3. 在JavaScript函数中,使用ajax发送请求来获取登录或注册页面的内容。 4. 将获取到的内容添加到弹窗中。 5. 显示弹窗。 下面是一个简单的示例: HTML代码: ``` <!-- 登录注册表单 --> <form id="loginForm" action="login.php" method="post"> <input type="text" name="username" placeholder="用户名"> <input type="password" name="password" placeholder="密码"> <button type="submit">登录</button> </form> <form id="registerForm" action="register.php" method="post"> <input type="text" name="username" placeholder="用户名"> <input type="password" name="password" placeholder="密码"> <input type="password" name="confirm_password" placeholder="确认密码"> <button type="submit">注册</button> </form> <!-- 登录注册弹窗 --> <div id="loginPopup" class="popup"> <div class="popup-content"></div> </div> <div id="registerPopup" class="popup"> <div class="popup-content"></div> </div> ``` CSS代码: ``` /* 弹窗样式 */ .popup { display: none; position: fixed; z-index: 999; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); } .popup-content { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: #fff; padding: 20px; border-radius: 5px; } ``` JavaScript代码: ``` function showLoginForm() { // 显示登录弹窗 var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("loginPopup").style.display = "block"; document.getElementById("loginPopup").innerHTML = this.responseText; } }; xhr.open("GET", "login_form.php", true); xhr.send(); } function showRegisterForm() { // 显示注册弹窗 var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("registerPopup").style.display = "block"; document.getElementById("registerPopup").innerHTML = this.responseText; } }; xhr.open("GET", "register_form.php", true); xhr.send(); } ``` 在上面的代码中,我们使用了两个JavaScript函数showLoginForm()和showRegisterForm(),分别用于显示登录和注册弹窗。这两个函数使用了ajax来异步获取登录和注册页面的内容,并将其添加到对应的弹窗中。 最后,我们可以在登录注册按钮上添加onclick事件来触发弹窗显示: ``` <button onclick="showLoginForm()">登录</button> <button onclick="showRegisterForm()">注册</button> ``` 这样,当用户点击登录或注册按钮时,就会弹出对应的弹窗显示登录或注册表单。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值