728x90
<div class="box">
<span class="input-wrap">
<input type="checkbox" id="checkId" name="checkId">
<label for="checkId"><span></span></label>
์์ด๋ ์ ์ฅ
</span>
<ul class="find">
<li class="idSearch" id="idSearch" style="cursor: hand; cursor: pointer">์์ด๋ ์ฐพ๊ธฐ</li>
<li class="pwSearch" id="pwSearch" style="cursor: hand; cursor: pointer">๋น๋ฐ๋ฒํธ ์ฐพ๊ธฐ</li>
</ul>
</div>
<script>
$(document).ready(function(){
// ์ ์ฅ๋ ์ฟ ํค๊ฐ์ ๊ฐ์ ธ์์ ID ์นธ์ ๋ฃ์ด์ค๋ค. ์์ผ๋ฉด ๊ณต๋ฐฑ์ผ๋ก ๋ค์ด๊ฐ.
var key = getCookie("key");
$("#id").val(key);
// ๊ทธ ์ ์ ID๋ฅผ ์ ์ฅํด์ ์ฒ์ ํ์ด์ง ๋ก๋ฉ ์, ์
๋ ฅ ์นธ์ ์ ์ฅ๋ ID๊ฐ ํ์๋ ์ํ๋ผ๋ฉด,
if($("#id").val() != ""){
$("#checkId").attr("checked", true); // ID ์ ์ฅํ๊ธฐ๋ฅผ ์ฒดํฌ ์ํ๋ก ๋๊ธฐ.
}
$("#checkId").change(function(){ // ์ฒดํฌ๋ฐ์ค์ ๋ณํ๊ฐ ์๋ค๋ฉด,
if($("#checkId").is(":checked")){ // ID ์ ์ฅํ๊ธฐ ์ฒดํฌํ์ ๋,
setCookie("key", $("#id").val(), 7); // 7์ผ ๋์ ์ฟ ํค ๋ณด๊ด
}else{ // ID ์ ์ฅํ๊ธฐ ์ฒดํฌ ํด์ ์,
deleteCookie("key");
}
});
// ID ์ ์ฅํ๊ธฐ๋ฅผ ์ฒดํฌํ ์ํ์์ ID๋ฅผ ์
๋ ฅํ๋ ๊ฒฝ์ฐ, ์ด๋ด ๋๋ ์ฟ ํค ์ ์ฅ.
$("#id").keyup(function(){ // ID ์
๋ ฅ ์นธ์ ID๋ฅผ ์
๋ ฅํ ๋,
if($("#checkId").is(":checked")){ // ID ์ ์ฅํ๊ธฐ๋ฅผ ์ฒดํฌํ ์ํ๋ผ๋ฉด,
setCookie("key", $("#id").val(), 7); // 7์ผ ๋์ ์ฟ ํค ๋ณด๊ด
}
});
// ์ฟ ํค ์ ์ฅํ๊ธฐ
// setCookie => saveidํจ์์์ ๋๊ฒจ์ค ์๊ฐ์ด ํ์ฌ์๊ฐ๊ณผ ๋น๊ตํด์ ์ฟ ํค๋ฅผ ์์ฑํ๊ณ ์ง์์ฃผ๋ ์ญํ
function setCookie(cookieName, value, exdays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var cookieValue = escape(value)
+ ((exdays == null) ? "" : "; expires=" + exdate.toGMTString());
document.cookie = cookieName + "=" + cookieValue;
}
// ์ฟ ํค ์ญ์
function deleteCookie(cookieName) {
var expireDate = new Date();
expireDate.setDate(expireDate.getDate() - 1);
document.cookie = cookieName + "= " + "; expires="
+ expireDate.toGMTString();
}
// ์ฟ ํค ๊ฐ์ ธ์ค๊ธฐ
function getCookie(cookieName) {
cookieName = cookieName + '=';
var cookieData = document.cookie;
var start = cookieData.indexOf(cookieName);
var cookieValue = '';
if (start != -1) { // ์ฟ ํค๊ฐ ์กด์ฌํ๋ฉด
start += cookieName.length;
var end = cookieData.indexOf(';', start);
if (end == -1) // ์ฟ ํค ๊ฐ์ ๋ง์ง๋ง ์์น ์ธ๋ฑ์ค ๋ฒํธ ์ค์
end = cookieData.length;
console.log("end์์น : " + end);
cookieValue = cookieData.substring(start, end);
}
return unescape(cookieValue);
}
</script>
'js' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[jQuery] ajax success html์์ ์ํ๋ ์์ ์ฐพ๊ธฐ (0) | 2021.09.15 |
---|---|
[jQuery] html() ์ append() ์ฐจ์ด (0) | 2021.09.15 |
[JavaScript] addEventListener() ์ด๋ฒคํธ ๋ฑ๋ก (0) | 2021.07.26 |
[JavaScript] Date ๋ ์ง ๊ฐ๋จ ํํ / toISOString() (0) | 2021.06.03 |
[jQuery] ๋ฒํผ์ด ํฌํจ๋ td์ ๋ถ๋ชจ tr index ๊ตฌํ๊ธฐ (2) | 2021.05.18 |