2016-11-24
JavaScript 전역 대상
정의 와 용법: escape () 함 수 는 문자열 을 인 코딩 할 수 있 습 니 다. 모든 컴퓨터 에서 이 문자열 을 읽 을 수 있 습 니 다.
문법: escape (string)
매개 변수 설명 string 필요: 전의 나 인 코딩 될 문자열 입 니 다.
반환 값: 인 코딩 된 string 의 복사 본 입 니 다.그 중 일부 문 자 는 16 진법 의 전의 서열 로 바 뀌 었 다.
설명: 이 방법 은 ASCII 자모 와 숫자 를 인 코딩 하지 않 고 아래 의 ASCII 문장 부 호 를 인 코딩 하지 않 습 니 다: * @ - +. /.다른 모든 문 자 는 전의 시퀀스 로 대 체 됩 니 다.
알림: unescape () 를 사용 하여 escape () 인 코딩 된 문자열 을 디 코딩 할 수 있 습 니 다.
설명: ECMAScript v3 는 이 방법 을 사용 하 는 것 을 반대 합 니 다. decodeURI () 와 decodeURIComponent () 를 사용 하여 대체 합 니 다.
인 스 턴 스: 이 예 에서 저 희 는 escape () 를 사용 하여 문자열 을 인 코딩 할 것 입 니 다.
document.write(escape("Visit W3School!") + "<br />")
document.write(escape("?!=()#%&"))
출력:
Visit%20W3School%21
%3F%21%3D%28%29%23%25%26
// cookie
function setCookie(cookieName,cookieValue,cookieExpires,cookiePath)
{
cookieValue = escape(cookieValue);// latin-1
if(cookieExpires=="")
{
var nowDate = new Date();
nowDate.setMonth(nowDate.getMonth()+6);
cookieExpires = nowDate.toGMTString();
}
if(cookiePath!="")
{
cookiePath = ";Path="+cookiePath;
}
document.cookie= cookieName+"="+cookieValue+";expires="+cookieExpires+cookiePath;
}
// cookie
function getCookieValue(cookieName)
{
var cookieValue = document.cookie;
var cookieStartAt = cookieValue.indexOf(""+cookieName+"=");
if(cookieStartAt==-1)
{
cookieStartAt = cookieValue.indexOf(cookieName+"=");
}
if(cookieStartAt==-1)
{
cookieValue = null;
}
else
{
cookieStartAt = cookieValue.indexOf("=",cookieStartAt)+1;
cookieEndAt = cookieValue.indexOf(";",cookieStartAt);
if(cookieEndAt==-1)
{
cookieEndAt = cookieValue.length;
}
cookieValue = unescape(cookieValue.substring(cookieStartAt,cookieEndAt));// latin-1
}
return cookieValue;
}
JavaScript indexOf () 방법
JavaScript String 대상
정의 와 용법: index Of () 방법 은 지정 한 문자열 값 이 문자열 에 처음 나타 난 위 치 를 되 돌려 줍 니 다.
문법: stringObject. indexOf (searchvalue, from index)
매개 변수 설명 searchvalue 가 필요 합 니 다.검색 할 문자열 값 을 지정 합 니 다.from index 에서 선택 할 수 있 는 정수 인자 입 니 다.문자열 에서 검색 을 시작 할 위 치 를 정 합 니 다.그것 의 합 법 적 인 수 치 는 0 에서 stringObject. length - 1 입 니 다.이 인 자 를 생략 하면 문자열 의 첫 글자 부터 검색 합 니 다.
설명: 이 방법 은 문자열 stringObject 를 처음부터 끝까지 검색 하여 하위 문자열 searchvalue 가 있 는 지 확인 합 니 다.검색 을 시작 하 는 위 치 는 문자열 의 from index 나 문자열 의 시작 (from index 가 지정 되 지 않 았 을 때) 입 니 다.searchvalue 를 찾 으 면 searchvalue 가 처음 나타 난 위 치 를 되 돌려 줍 니 다.stringObject 의 문자 위 치 는 0 에서 시 작 됩 니 다.
주석: index Of () 방법 은 대소 문자 에 민감 합 니 다!
설명: 검색 할 문자열 값 이 나타 나 지 않 으 면 - 1 을 되 돌려 줍 니 다.
cookie
JavaScript</a>" type="text/javascript">
// cookie
function getCookieValue(cookieName)
{
var cookieValue = document.cookie;
var cookieStartAt = cookieValue.indexOf(""+cookieName+"=");
if(cookieStartAt==-1)
{
cookieStartAt = cookieValue.indexOf(cookieName+"=");
}
if(cookieStartAt==-1)
{
cookieValue = null;
}
else
{
cookieStartAt = cookieValue.indexOf("=",cookieStartAt)+1;
cookieEndAt = cookieValue.indexOf(";",cookieStartAt);
if(cookieEndAt==-1)
{
cookieEndAt = cookieValue.length;
}
cookieValue = unescape(cookieValue.substring(cookieStartAt,cookieEndAt));// latin-1
}
return cookieValue;
}
// cookie
function setCookie(cookieName,cookieValue,cookieExpires,cookiePath)
{
cookieValue = escape(cookieValue);// latin-1
if(cookieExpires=="")
{
var nowDate = new Date();
nowDate.setMonth(nowDate.getMonth()+6);
cookieExpires = nowDate.toGMTString();
}
if(cookiePath!="")
{
cookiePath = ";Path="+cookiePath;
}
document.cookie= cookieName+"="+cookieValue+";expires="+cookieExpires+cookiePath;
}
//
function window_onload()
{
var userNameElem = document.getElementById("userName");//
var passwordElem = document.getElementById("password");//
var currUserElem = document.getElementById("currUser");//
var currUser = getCookieValue("currUser");
if(currUser!=null)
{
userNameElem.value=currUser;
currUserElem.checked = true;
}
if(userNameElem.value!="")
{
passwordElem.focus();//
}
else
{
currUserElem.focus();//
}
}
//
function login()
{
var userNameElem = document.getElementById("userName");
var passwordElem = document.getElementById("password");
var currUserElem = document.getElementById("currUser");
if(userNameElem.value=="" || passwordElem.value=="")
{
alert(" !");
if(userNameElem.value=="")
{
userNameElem.focus();//
}
else
{
passwordElem.focus();//
}
return false;
}
if(currUserElem.checked)
{
setCookie("currUser",userNameElem.value,"","");// cookie
}
else
{
var nowDate = new Date();//
nowDate.setMonth(nowDate.getMonth()-2);// cookie
cookieExpires = nowDate.toGMTString();// GMT
setCookie("userName","",cookieExpires,"");// cookie
}
return true;
}
주의:
구 글 크롬 브 라 우 저 는 보안 을 위해 온라인 - cookie 만 지원 하기 때문에 로 컬 테스트 에 서 는 효과 가 없습니다. 서버 에 업로드 해 보 세 요.
blur 초점 잃 기
포커 스
index([selector|element])
개요: 일치 하 는 요 소 를 검색 하고 해당 요소 의 색인 값 을 되 돌려 0 부터 계산 합 니 다.만약 에 index () 방법 에 인 자 를 전달 하지 않 으 면 반환 값 은 바로 이 jQuery 대상 집합 에서 첫 번 째 요소 가 또래 요소 에 비해 위치 하 는 것 입 니 다.매개 변수 가 DOM 요소 나 jQuery 대상 이 라면 반환 값 은 전달 하 는 요소 가 원래 집합 한 위치 에 비해 전달 하 는 것 입 니 다.매개 변수 가 선택 기 라면 되 돌아 오 는 값 은 선택 기 와 일치 하 는 요소 의 위치 입 니 다.일치 하 는 요 소 를 찾 지 못 하면 - 1 을 되 돌려 줍 니 다.구체 적 으로 예 시 를 참고 하 세 요.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.