我有一个 javascript 函数,当我单击输入以在用户填写表单时显示提示时显示或隐藏“spans”:
function prepareInputsForHints() {
var inputs = document.getElementsByTagName("input");
for (var i=0; i<inputs.length; i++){
// test to see if the hint span exists first
if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
// the span exists! on focus, show the hint
inputs[i].onfocus = function () {
this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
}
// when the cursor moves away from the field, hide the hint
inputs[i].onblur = function () {
this.parentNode.getElementsByTagName("span")[0].style.display = "none";
}
}
}
}
我的问题是,当我尝试向提示文本添加链接时,用户无法单击它,因为它首先注册了 onblur 事件并且提示消失了,所以我想知道如何修改此函数以使其不会单击提示时隐藏。