日期:2014-05-17 浏览次数:20573 次
input.placeholder {color:#999}
<script src="http://a.tbcdn.cn/s/kissy/1.1.6/kissy-min.js"></script> <script> //本代码发布在 http://seavers.iteye.com/ , 未经同意,谢绝转载 //模拟了placeholder 80%的功能 (function() { var S=KISSY, Dom = S.DOM, Event = S.Event; S.namespace("HTML5"); S.HTML5.placeholder = { support : "placeholder" in document.createElement("input"), activate : (function() { function _showPlaceholder(el, className, value) { if (!Dom.hasClass(el, className) && !el.value) { el.value = value; Dom.addClass(el, className); } } function _hidePlaceholder(el, className, value) { if (Dom.hasClass(el, className)) { el.value = value; Dom.removeClass(el, className); } } function _activatePlaceholder(selector) { var ATTR = "placeholder", CLASS = "placeholder"; S.each(S.query(selector), function(el){ var TIP = el.getAttribute(ATTR); if (!TIP) return ; Event.on(el.form, 'submit', function(ev) { _hidePlaceholder(el, CLASS, ""); }); Event.on(window, 'unload', function(ev) { //解决firefox3.6刷新问题 _hidePlaceholder(el, CLASS, ""); }); Event.on(el, 'focusin', function(ev){ _hidePlaceholder(el, CLASS, ""); }); Event.on(el, 'focusout', function(ev){ _showPlaceholder(el, CLASS, TIP); }); _showPlaceholder(el, CLASS, TIP); }); } return _activatePlaceholder; })() }; //如果有原生的placeholder,使用原生,否则使用模拟的 if (!S.HTML5.placeholder.support) { S.HTML5.placeholder.activate('INPUT'); } })(); </script>