Skip to content

Instantly share code, notes, and snippets.

@elegantcoder
Created July 14, 2012 16:06
Show Gist options
  • Save elegantcoder/3111929 to your computer and use it in GitHub Desktop.
Save elegantcoder/3111929 to your computer and use it in GitHub Desktop.
입력 필드 내에 텍스트 표시 UI 의 예제 코드
<label for="ex1-pw-input" style="display:none;">비밀번호</label>
<input type="password" value="비밀번호" data-placeholder="비밀번호" id="ex1-pw-input" />
<label for="ex1-id-input" style="display:none;">이메일 주소</label>
<input type="text" value="이메일 주소" data-placeholder="이메일 주소" id="ex1-id-input" />
(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);
<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>
(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);
<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>
<label for="ex2-pw-input" style="display:none;">비밀번호</label>
<input type="password" value="" id="ex2-pw-input" class="ex2-pw-on" />
(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