㈠ 如何编写一个自动登录的js脚本
$(function(){
varname1=getCookie('name1');
varname2=getCookie('name2');
varname5=getCookie('name5');
dataForm="name1="+name1+"&name2="+name2+"&name5="+name5;
$.ajax({
type:"POST",
url:"login.php",
data:dataForm,
success:function(msg){
varstr=eval('('+msg+')');
//判断
}
});
});
functiongetCookie(c_name){
if(document.cookie.length>0){
c_start=document.cookie.indexOf(c_name+"=")
if(c_start!=-1){
c_start=c_start+c_name.length+1
c_end=document.cookie.indexOf(";",c_start)
if(c_end==-1)c_end=document.cookie.length
returnunescape(document.cookie.substring(c_start,c_end))
}
}
return"";
}
</script>
㈡ 鍒ゆ柇鐢ㄦ埛鍚嶏紝瀵嗙爜锛岄獙璇佺爜閮借緭鍏ュ悗鎵嶅惎鍔ㄧ櫥褰曟寜閽甹s鎬庝箞鍐
鍋囪剧敤鎴峰悕杈撳叆妗嗙殑id涓衡渦sername鈥濓紝瀵嗙爜杈撳叆妗嗙殑id涓衡減assword鈥濓紝楠岃瘉鐮佽緭鍏ユ嗙殑id涓衡渧erify鈥濓紝鐧诲綍鎸夐挳鐨刬d涓衡渓ogin鈥濓紝鍙浠ヤ娇鐢ㄤ互涓嬩唬鐮佸疄鐜帮細``` javascriptconst usernameInput = document.getElementById(\"username\"); // 鑾峰彇鐢ㄦ埛鍚嶈緭鍏ユ哻onst passwordInput = document.getElementById(\"password\"); // 鑾峰彇瀵嗙爜杈撳叆妗哻onst verifyInput = document.getElementById(\"verify\"); // 鑾峰彇楠岃瘉鐮佽緭鍏ユ哻onst loginButton = document.getElementById(\"login\"); // 鑾峰彇鐧诲綍鎸夐挳// 鐩戝惉杈撳叆妗嗙殑杈撳叆浜嬩欢usernameInput.addEventListener(\"input\", checkInput);passwordInput.addEventListener(\"input\", checkInput);verifyInput.addEventListener(\"input\", checkInput);// 妫鏌ヨ緭鍏ユ嗘槸鍚﹂兘鏈夎緭鍏function checkInput() { if (usernameInput.value \u0026\u0026 passwordInput.value \u0026\u0026 verifyInput.value) { loginButton.removeAttribute(\"disabled\"); // 鍚鐢ㄧ櫥褰曟寜閽 } else { loginButton.setAttribute(\"disabled\", \"disabled\"); // 绂佺敤鐧诲綍鎸夐挳 }}```杩欐典唬鐮佷腑锛屼娇鐢╝ddEventListener鏂规硶涓烘瘡涓杈撳叆妗嗘坊鍔犱簡鈥渋nput鈥濅簨浠剁殑鐩戝惉鍣锛屽綋鐢ㄦ埛杈撳叆鏃讹紝浼氳嚜鍔ㄨЕ鍙慶heckInput鍑芥暟銆俢heckInput鍑芥暟浼氭鏌ヤ笁涓杈撳叆妗嗘槸鍚﹂兘鏈夎緭鍏ワ紝濡傛灉閮芥湁杈撳叆锛屽垯鍚鐢ㄧ櫥褰曟寜閽锛屽惁鍒欑佺敤鐧诲綍鎸夐挳銆
㈢ js点击记住账号实现记住用户名和密码
<!doctypehtml>
<htmllang="en">
<head>
<metacharset="UTF-8">
<title>Document</title>
</head>
<body>
账号:<input>
密码:<input>
记住密码:<inputtype="checkbox">
<buttononclick="fn()">登录</button>
<script>
varuser=document.getElementsByTagName("input")[0],
pass=document.getElementsByTagName("input")[1],
check=document.getElementsByTagName("input")[2],
loUser=localStorage.getItem("user")||"";
loPass=localStorage.getItem("pass")||"";
user.value=loUser;
pass.value=loPass;
if(loUser!==""&&loPass!==""){
check.setAttribute("checked","");
}
functionfn(){
if(check.checked){
localStorage.setItem("user",user.value);
localStorage.setItem("pass",pass.value);
}else{
localStorage.setItem("user","");
localStorage.setItem("pass","");
}
}
</script>
</body>
</html>
㈣ 用javascript实现登录界面帐号密码正确后转换页面
修改check函数
function check(){
var user = "user", password = "123456";
var temUser = document.form1.username.value;
var temPassword = document.form1.password.value;
if(user==temUser && password==temPassword)
{
alert("登入成功!");
window.location.href="登陆后显示的页面";//在这里进行页面跳转内
}
else{
alert("用户名或密容码错误!");
//这里可以跳转到错误提示页面,或者不跳转
}
}
㈤ js连接数据库验证登录名和密码正确
连接oracle、mysql之类的,可以通过js访问后台程序操作数据库(js不能直接访问);连接sql server和Access数据库,则可以通过微软的ActiveX技术连接数据库:
//连接sql server
<script language="javascript">
var conn = new ActiveXObject("ADODB.Connection");
conn.Open("Provider=SQLOLEDB.1; Data Source=yourDS; User ID=yourUserId; "
+"Password=sasa; Initial Catalog=MyBulletin");
var rs = new ActiveXObject("ADODB.Recordset");
var sql="select * from user where username='myname' and password='mypwd密文'";
rs.open(sql, conn);
alert(rs(0));
rs.close();
rs = null;
conn.close();
conn = null;
</script>
//连接ACCESS
<script language="javascript">
function conn(){
var db_bbs="yourDBName.mdb";
var conn = new ActiveXObject("ADODB.Connection");
conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+db_bbs+"");
var rs = new ActiveXObject("ADODB.Recordset");
var sql="select * from user where username='myname' and password='mypwd密文'";
rs.open(sql,conn);
alert(rs(0));
conn.close();
conn = null;
}
</script>
㈥ 前端JS 怎么实现用户登陆之后点各个页面都不用再登陆
给你说个思路吧!
登录成功之后,把登录信息加密后保存在cookie里面;
然后建一个js文件,在这个文件里面做用户是否已登录的判断!如果登录了就直接显示该页面,如果没登录,就跳转回登录页面!
这个js文件在登录后才能看到的页面都做引用;
㈦ 用javascript编写一段用户名和密码登录代码。点击登录按钮后,页面跳转到另一个页面,显示此用户名和密码的
function login()
{
var username=document.getElementById("userName");
var password=document.getElementById("password");
if(username.value=="admin"&&password.value="123456")
{
window.location.href="success.html";
}
}
为登录按钮注册onclick=“login()”