gpt4 book ai didi

javascript - jquery 显示提示功能无法在基于 webkit 的浏览器中工作

转载 作者:行者123 更新时间:2023-11-29 22:26:54 25 4
gpt4 key购买 nike

我有一个 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/

最佳答案

尝试替换你的代码行:

if(span instanceof HTMLSpanElement) {

接下来:

if(span && span.tagName.toUpperCase()==="SPAN") {

http://jsfiddle.net/eZnYY/3/在桌面 Safary 和 Android 浏览器(模拟器)上检查

关于javascript - jquery 显示提示功能无法在基于 webkit 的浏览器中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8952687/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com