㈠ 如何編寫一個自動登錄的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()」