前端页面设置重置按钮或刷新按钮


下面以三个页面分别命名为frame.html、top.html、bottom.html为例来具体说明如何做。 
frame.html 由上(top.html)下(bottom.html)两个页面组成,代码如下: 

复制代码 代码如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> 
<HEAD> 
<TITLE> frame </TITLE> 
</HEAD> 
<frameset rows="50%,50%"> 
<frame name=top src="top.html"> 
<frame name=bottom src="bottom.html"> 
</frameset> 
</HTML> 

现在假设top.html (即上面的页面) 有七个button来实现对bottom.html (即下面的页面) 的刷新,可以用以下七种语句,哪个好用自己看着办了。
top.html 页面的代码如下: 

代码如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> 
<HEAD> 
<TITLE>top.html </TITLE> 
</HEAD> 
<BODY> 
//七种方式
1.  <button onclick="window.parent.frames[1].location.reload()" class="layui-btn layui-btn-sm layui-btn-primary"><i class="layui-icon layui-icon-refresh"></i>重置1</button>
2.  <button onclick="window.parent.frames.bottom.location.reload()" class="layui-btn layui-btn-sm layui-btn-primary"><i class="layui-icon layui-icon-refresh"></i>重置2</button>
3.   <button onclick="window.parent.frames['bottom'].location.reload()" class="layui-btn layui-btn-sm layui-btn-primary"><i class="layui-icon layui-icon-refresh"></i>重置3</button>
4.   <button onclick="window.parent.frames.item(1).location.reload()" class="layui-btn layui-btn-sm layui-btn-primary"><i class="layui-icon layui-icon-refresh"></i>重置4</button>
5.    <button onclick="window.parent.frames.item('bottom').location.reload()" class="layui-btn layui-btn-sm layui-btn-primary"><i class="layui-icon layui-icon-refresh"></i>重置5</button>
6.    <button onclick="window.parent.bottom.location.reload()" class="layui-btn layui-btn-sm layui-btn-primary"><i class="layui-icon layui-icon-refresh"></i>重置6</button>
7.   <button onclick="window.parent['bottom'].location.reload()" class="layui-btn layui-btn-sm layui-btn-primary"><i class="layui-icon layui-icon-refresh"></i>重置7</button>
</BODY> 
</HTML> 

下面是bottom.html页面源代码,为了证明下方页面的确被刷新了,在装载完页面弹出一个对话框。 

复制代码 代码如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> 
<HEAD> 
<TITLE> bottom.html </TITLE> 
</HEAD> 
<BODY onload="alert('666666666666!')"> 
<h1>This is the content in bottom.html.</h1> 
</BODY> 
</HTML> 

解释: 
1.window指代的是当前页面,例如对于此例它指的是top.html页面。 
2.parent指的是当前页面的父页面,也就是包含它的框架页面。例如对于此例它指的是framedemo.html。 
3.frames是window对象,是一个数组。代表着该框架内所有子页面。 
4.item是方法。返回数组里面的元素。 
5.如果子页面也是个框架页面,里面还是其它的子页面,那么上面的有些方法可能不行。 
附: 
Javascript刷新页面的几种方法: 
1 history.go(0) 
2 location.reload() 
3 location=location 
4 location.assign(location) 
5 document.execCommand('Refresh') 
6 window.navigate(location) 
7 location.replace(location) 
8 document.URL=location.href 

二、自动刷新页面 
1.页面自动刷新:把如下代码加入<head>区域中 
<meta http-equiv="refresh" content="20"> 
其中20指每隔20秒刷新一次页面. 
2.页面自动跳转:把如下代码加入<head>区域中 
<meta http-equiv="refresh" content="20;url=http://www.jb51.net"> 
其中20指隔20秒后跳转到http://www.jb51.net页面 
3.页面自动刷新js版 

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
以下是一个带有重置按钮的PHP登录页面的示例代码: ```php <?php // 检查表单是否提交 if(isset($_POST['login'])) { // 获取输入的用户名和密码 $username = $_POST['username']; $password = $_POST['password']; // 在此处添加验证用户名和密码的代码,比如与数据库中的用户信息进行比对 // 简单示例:检查用户名和密码是否匹配 if($username === 'admin' && $password === 'password') { // 登录成功,跳转到欢迎页面 header('Location: welcome.php'); exit; } else { // 登录失败,显示错误消息 $error = "Invalid username or password."; } } // 处理重置按钮的点击事件 if(isset($_POST['reset'])) { $username = ''; $password = ''; } ?> <!DOCTYPE html> <html> <head> <title>Login Page</title> </head> <body> <h1>Login</h1> <?php if(isset($error)): ?> <p><?php echo $error; ?></p> <?php endif; ?> <form method="POST" action=""> <label for="username">Username:</label> <input type="text" id="username" name="username" value="<?php echo htmlentities($username); ?>" required><br> <label for="password">Password:</label> <input type="password" id="password" name="password" value="<?php echo htmlentities($password); ?>" required><br> <input type="submit" name="login" value="Login"> <input type="submit" name="reset" value="Reset"> </form> </body> </html> ``` 在上面的代码中,我添加了一个名为`reset`的重置按钮。当用户点击重置按钮时,`$_POST['reset']`将被设置为`true`,然后我们可以在PHP代码中处理重置按钮的点击事件。在这个示例中,我将用户名和密码的值重置为空字符串。 在HTML表单中,我使用了`value="<?php echo htmlentities($username); ?>"`来设置输入字段的初始值。这样,当用户点击重置按钮时,输入字段中的值将被重置为空字符串。 请注意,这只是一个简单的示例,并不包含真实的用户验证和安全性措施。在实际项目中,请确保在处理用户输入时进行适当的验证和过滤,以防止安全漏洞。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jq1223

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值