我有一个 jquery 函数,当我单击表单上的输入字段时,它显示/隐藏看起来像“提示”的跨度。
该功能在 FirfFox、Chrome、IE(!) :) 等上运行良好。但在基于 webkit 的浏览器(即 Safari 和 Android)上则完全不适用(已测试)
$(function(prepareInputsForHints) {
var inputs = document.getElementsByTagName("input");
for (var i=0; i<inputs.length; i++){
(function(i) {
// Let the code cleane
var span = inputs[i].nextElementSibling;
if(span instanceof HTMLSpanElement) {
if(span.className == "hint") {
span.onmouseover = function() { this.isOver = true; }
span.onmouseout = function() { this.isOver = false; if(!inputs[i].isFocus) inputs[i].onblur(); }
// the span exists! on focus, show the hint
inputs[i].onfocus = function () {
this.isFocus = true;
span.style.display = "inline";
}
// when the cursor moves away from the field, hide the hint
inputs[i].onblur = function () {
this.isFocus = false;
if(!span.isOver) span.style.display = "none";
}
}
}
})(i);
}
});
另外,为了您的方便,我为您提供http://jsfiddle.net/eZnYY/1/