Created
July 14, 2012 16:06
-
-
Save elegantcoder/3111929 to your computer and use it in GitHub Desktop.
입력 필드 내에 텍스트 표시 UI 의 예제 코드
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<label for="ex1-pw-input" style="display:none;">비밀번호</label> | |
<input type="password" value="비밀번호" data-placeholder="비밀번호" id="ex1-pw-input" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<label for="ex1-id-input" style="display:none;">이메일 주소</label> | |
<input type="text" value="이메일 주소" data-placeholder="이메일 주소" id="ex1-id-input" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function example1($) { | |
var $id = $('#ex1-id-input') | |
var $pw = $('#ex1-pw-input') | |
var onfocus = function () { | |
$(this).val('') | |
} | |
var onblur = function () { | |
var $this = $(this) | |
if ($.trim($this.val()).length === 0) { | |
$this.val($this.attr('data-placeholder')) | |
} | |
} | |
$id.on('click focus', onfocus).on('blur', onblur); | |
$pw.on('click focus', onfocus).on('blur', onblur); | |
})(jQuery); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div style="position:relative;"> | |
<label for="ex3-pw-input" style="position:absolute;left:4px;top:8px;">비밀번호</label> | |
<input type="password" style="position:absolute;z-index:2;background-color:transparent;" value="" id="ex3-pw-input" /> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function example3($) { | |
var $pw = $('#ex3-pw-input') | |
$pw.on('click focus', function () { | |
$(this).siblings('label').hide() | |
}); | |
$pw.on('blur', function () { | |
$this = $(this) | |
if ($.trim($this.val()).length === 0) { | |
$this.siblings('label').show() | |
} | |
}); | |
})(jQuery); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div style="position:relative;"> | |
<label for="ex4-pw-input" style="position:absolute;left:4px;top:8px;">비밀번호</label> | |
<input type="password" style="position:absolute;z-index:2;background:url('./transparent.gif') repeat 0 0 ;" value="" id="ex4-pw-input" /> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<label for="ex2-pw-input" style="display:none;">비밀번호</label> | |
<input type="password" value="" id="ex2-pw-input" class="ex2-pw-on" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function example2($) { | |
var $pw = $('#ex2-pw-input') | |
$pw.on('click focus', function () { | |
$(this).removeClass('ex2-pw-on'); | |
}); | |
$pw.on('blur', function () { | |
var $this = $(this) | |
if ($.trim($this.val()).length === 0) { | |
$this.addClass('ex2-pw-on'); | |
} | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment