为什么提交用户名和密码后 点击退回按钮提交的用户名和密码还在文本框?
退回后就是图片里面的样子 怎样让他自动清空呢
<code> <meta charset="utf-8"> <title> </title> <style type="text/css"> div input{display: inline-block;width: 200px;height: 20px;border:1px solid #ccc;} div .span1{display: inline-block;width: 90px;height: 20px;text-align: left;margin-top: 20px;} div #sp1,#sp2,#sp3,#sp4{display: inline-block;width: 160px;height: 20px;} </style> <script src="ajax.js"></script> <script type="text/javascript"> window.onload=function(){ var oInput=document.getElementsByTagName('input'); var oIpt1=document.getElementById('ipt1'); var oIpt2=document.getElementById('ipt2'); var oIpt3=document.getElementById('ipt3'); var oIpt4=document.getElementById('ipt4'); var oSp1=document.getElementById('sp1'); var oSp2=document.getElementById('sp2'); var oSp3=document.getElementById('sp3'); var oSp4=document.getElementById('sp4'); var re=/^[\w]{6,12}$/; oIpt1.onblur=function(){ if(oIpt1.value==''){ this.style.border='1px solid red'; }else{ ajax("nameajax.php?id="+oIpt1.value,function(str){ oSp1.innerHTML=str; }) } }; oIpt2.onblur=function(){ if(oIpt2.value==''){ this.style.border='1px solid red'; }else{ if(oIpt2.value.match(re)){ oSp2.innerHTML='密码合法'; }else{ oSp2.innerHTML='密码不合法'; } } } oIpt3.onblur=function(){ if(oIpt3.value==''){ this.style.border='1px solid red'; }else{ if(oIpt2.value==oIpt3.value){ oSp3.innerHTML='密码正确'; }else{ oSp3.innerHTML='密码不一致'; } } }; oIpt4.onblur=function(){ if(oIpt4.value==''){ this.style.border='1px solid red'; }else{ ajax("emailajax.php?id="+oIpt4.value,function(str){ oSp4.innerHTML=str; }) } }; }; </script> <div> <form action="reg.php" method="post"> <span class="span1">用 户 名:</span><input type="text" id="ipt1" name="username" autocomplete="off"><span id="sp1"></span><br> <span class="span1">密 码:</span><input type="password" id="ipt2" autocomplete="off"><span id="sp2"></span><br> <span class="span1">确认密码:</span><input type="password" id="ipt3" name="password" autocomplete="off"><span id="sp3"></span><br> <span class="span1">邮 箱:</span><input type="text" id="ipt4" name="email" autocomplete="off"><span id="sp4"></span><br> <button type="submit">提交</button> </form> </div> </code>
<code><?php $pdo=new PDO("mysql:host=localhost;dbname=t1","root",""); $stmt=$pdo->prepare("insert into user(username,password,email) values (:username,:password,:email)"); $stmt->execute($_POST); ?></code>
回复内容:
退回后就是图片里面的样子 怎样让他自动清空呢
<code> <meta charset="utf-8"> <title> </title> <style type="text/css"> div input{display: inline-block;width: 200px;height: 20px;border:1px solid #ccc;} div .span1{display: inline-block;width: 90px;height: 20px;text-align: left;margin-top: 20px;} div #sp1,#sp2,#sp3,#sp4{display: inline-block;width: 160px;height: 20px;} </style> <script src="ajax.js"></script> <script type="text/javascript"> window.onload=function(){ var oInput=document.getElementsByTagName('input'); var oIpt1=document.getElementById('ipt1'); var oIpt2=document.getElementById('ipt2'); var oIpt3=document.getElementById('ipt3'); var oIpt4=document.getElementById('ipt4'); var oSp1=document.getElementById('sp1'); var oSp2=document.getElementById('sp2'); var oSp3=document.getElementById('sp3'); var oSp4=document.getElementById('sp4'); var re=/^[\w]{6,12}$/; oIpt1.onblur=function(){ if(oIpt1.value==''){ this.style.border='1px solid red'; }else{ ajax("nameajax.php?id="+oIpt1.value,function(str){ oSp1.innerHTML=str; }) } }; oIpt2.onblur=function(){ if(oIpt2.value==''){ this.style.border='1px solid red'; }else{ if(oIpt2.value.match(re)){ oSp2.innerHTML='密码合法'; }else{ oSp2.innerHTML='密码不合法'; } } } oIpt3.onblur=function(){ if(oIpt3.value==''){ this.style.border='1px solid red'; }else{ if(oIpt2.value==oIpt3.value){ oSp3.innerHTML='密码正确'; }else{ oSp3.innerHTML='密码不一致'; } } }; oIpt4.onblur=function(){ if(oIpt4.value==''){ this.style.border='1px solid red'; }else{ ajax("emailajax.php?id="+oIpt4.value,function(str){ oSp4.innerHTML=str; }) } }; }; </script> <div> <form action="reg.php" method="post"> <span class="span1">用 户 名:</span><input type="text" id="ipt1" name="username" autocomplete="off"><span id="sp1"></span><br> <span class="span1">密 码:</span><input type="password" id="ipt2" autocomplete="off"><span id="sp2"></span><br> <span class="span1">确认密码:</span><input type="password" id="ipt3" name="password" autocomplete="off"><span id="sp3"></span><br> <span class="span1">邮 箱:</span><input type="text" id="ipt4" name="email" autocomplete="off"><span id="sp4"></span><br> <button type="submit">提交</button> </form> </div> </code>
<code><?php $pdo=new PDO("mysql:host=localhost;dbname=t1","root",""); $stmt=$pdo->prepare("insert into user(username,password,email) values (:username,:password,:email)"); $stmt->execute($_POST); ?></code>
浏览器问题吧,我之前用火狐好像也会出现这个问题。
在form里面添加
js代码添加
$("input[type=reset]").trigger("click"); //jquery提供的方法
或者遍历表单内的元素清空内容。
我这里有个链接你可以参考下http://www.cnblogs.com/shanlin/archive/2014/07/17/3850417.html
现在浏览器一般有自动保存用户名和密码的行为,可以使用js将用户名和密码设置成空:
var oIpt1=document.getElementById('ipt1');
var oIpt2=document.getElementById('ipt2');
oIpt1.value = '';
oIpt2.value = '';
使用ajax 提交登陆,只要就不会存在后退了

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c
