http://tacamy.github.io/jquery.placeholder/
Polyfill of placeholder exists already a lot. In the case the polifil rewrites the value of the textbox, It conflict with JavaScript to manipulate the form. So, I made a polifil of placeholder that does not rewrite the value.
- If the browser is compatible with the placeholder, it does not work.
- Overlay the transparent
span
on the textbox, and reproduce the pseudo-placeholder.
placeholderのpolyfillはすでにたくさん存在しますが、テキストボックスのvalue
を書き換えるpolyfillはフォームを操作する他のJavaScriptと相性が悪いため、value
を書き換えないpolyfillを作りました。
- attr属性がデフォルトの
'placeholder'
の場合は、ブラウザがplaceholderに対応している場合は何もしない - テキストボックスの上に透明の
span
を重ねて、擬似的にplaceholderを再現
<input type="text" value="" placeholder="placeholder text">
<textarea placeholder="placeholder text"></textarea>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="jquery.placeholder.js"></script>
<script>
$('[placeholder]').placeholder();
</script>
$('[placeholder]').placeholder({
attr : 'title',
color : '#999',
wrapper : 'wrapper',
overlay : 'overlay'
});
If you want to change the attribute of the placeholder text, please set the attribute.
default: placeholder
In the case of the attr: 'placeholder'
, it is a modern browser does not do anything, but otherwise it will work with all browsers.
If you want to change the color of the placeholder text, please set the color code.
default: '#AAA'
If you want to change the class name of the wrapper element, please set the class name.
default: 'placeholder-wrapper'
If you want to change the class name of the overlay element, please set the class name.
default: 'placeholder-ovarlay'
IE6+ and other new browsers.
1.1.0 : Corresponding to the percentage specified in the textbox.
1.1.0 : テキストボックスのwidth
に%
を指定しても崩れないように修正
This plugin is available under the MIT license.