Amy*_*y B 0 javascript html5 internet-explorer mootools placeholder
其他人问过这个,但答案都是针对jQuery的.
首先,你应该使用MooTools的插件"OverText" http://mootools.net/docs/more/Forms/OverText基本上模拟了这种功能.它实际上可以在任何浏览器中工作,因此,如果您愿意,可以使用它并完全忘记占位符属性.但是,如果您希望在可用时支持占位符,但是对于旧版浏览器使用OverText,则可以这样做:
window.addEvent('domready', function() {
// create a test element
var test = new Element('input');
// if it has 'placeholder' this browser supports it already so you can exit
if(("placeholder" in test)) { return; }
// for older browsers, get all the inputs which you have assigned a 'placeholder' attribute to
$$('input[placeholder]').each(function(el) {
// and create an overtext for them using the value of the placeholder attribute
new OverText(el, { textOverride: el.get('placeholder') });
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1537 次 |
| 最近记录: |