表單項 hover 時背景變色、同時顯示輔助說明文字(<dfn>),純 CSS + 輕量 JS 相容 IE6。
#need li {
height: 26px; width: 600px;
font: 12px/26px Arial, Helvetica, sans-serif;
background: #FFD;
border-bottom: 1px dashed #E0E0E0;
padding: 7px 0 7px 10px;
cursor: text;
}
#need li:hover, #need li.hover { background: #FFE8E8; }
#need input {
line-height: 14px; height: 14px; width: 200px;
border: 1px solid #E0E0E0; vertical-align: middle; padding: 6px;
}
#need dfn { display: none; }
#need li:hover dfn, #need li.hover dfn {
display: inline; margin-left: 7px; color: #676767;
}
function suckerfish(type, tag, parentId) {
if (window.attachEvent) { // 僅 IE 需要
window.attachEvent('onload', function() {
var els = parentId ? document.getElementById(parentId).getElementsByTagName(tag)
: document.getElementsByTagName(tag);
type(els);
});
}
}
function hover(els) {
for (var i=0; i<els.length; i++) {
els[i].onmouseover = function() { this.className += ' hover'; };
els[i].onmouseout = function() {
this.className = this.className.replace(new RegExp(' hover\\b'), '');
};
}
}
suckerfish(hover, 'li', 'need');
<ol id="need">
<li><label class="old_password">原始密碼:</label>
<input type='password' /></li>
<li><label class="new_password">新的密碼:</label>
<input type='password' />
<dfn>(密碼長度為6~20字節。不想修改請留空)</dfn></li>
<li><label class="rePassword">重複密碼:</label>
<input type='password' /></li>
<li><label class="email">郵箱設置:</label>
<input type='text' />
<dfn>(承諾絕不發送垃圾郵件。)</dfn></li>
</ol>
CSS :hover 處理現代瀏覽器,JS suckerfish 補足 IE6,<dfn> 語義化承載提示文字,體驗流暢。