Created
May 23, 2014 05:21
-
-
Save YusukeHirao/c6c4345530f74e55217a to your computer and use it in GitHub Desktop.
input[placeholder] IE8対応メモ そのうちリファクタリング&プラグイン化する
This file contains 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
$(document).ready(function(){ | |
var isIE8 = document.getElementsByClassName == null; | |
var dColor = '#999999'; //ヒント(初期値)の文字色 | |
var fColor = '#373331'; //通常入力時の文字色 | |
var $inputHint = $('.input_hint'); | |
var defaultValue = $inputHint.val(); | |
var placeholder = $inputHint.attr('placeholder'); | |
if (isIE8) { | |
//初期状態の文字色 | |
if (defaultValue) { | |
$inputHint.css('color', fColor); | |
} else { | |
$inputHint.css('color', dColor); | |
$inputHint.val(placeholder); | |
} | |
//フォーカスされたときの処理 | |
$inputHint.focus(function(){ | |
var $this = $(this); | |
if (isIE8 && $this.val() === placeholder) { | |
$this.val(''); | |
$this.css('color', fColor); | |
} | |
}) | |
//フォーカスが外れたときの処理 | |
.blur(function(){ | |
var $this = $(this); | |
if (isIE8 && ($this.val() === defaultValue) || ($this.val() === '')) { | |
$this.val(placeholder); | |
$this.css('color',dColor); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment