Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 同一行数据后的绝对位置_Javascript_Css_Tooltip - Fatal编程技术网

Javascript 同一行数据后的绝对位置

Javascript 同一行数据后的绝对位置,javascript,css,tooltip,Javascript,Css,Tooltip,我正在尝试在输入框之后添加自定义工具提示,我让它工作正常,除了提交表单时出现错误。由于某些原因,工具提示会阻止错误文本。这很奇怪,我绞尽脑汁想了太久才明白 这一页有问题 我只有前四个输入的工具提示。在您提交显示错误的表单之前,它们工作正常。单击submit查看异常行为 最终目标是使工具提示出现在错误文本上,然后在您返回/单击另一个字段时消失并显示错误文本 有什么想法吗 function addLoadEvent(func) { var oldonload = window.onload;

我正在尝试在输入框之后添加自定义工具提示,我让它工作正常,除了提交表单时出现错误。由于某些原因,工具提示会阻止错误文本。这很奇怪,我绞尽脑汁想了太久才明白

这一页有问题

我只有前四个输入的工具提示。在您提交显示错误的表单之前,它们工作正常。单击submit查看异常行为

最终目标是使工具提示出现在错误文本上,然后在您返回/单击另一个字段时消失并显示错误文本

有什么想法吗

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

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";
            }
        }
    }
    // repeat the same tests as above for selects
    var selects = document.getElementsByTagName("select");
    for (var k = 0; k < selects.length; k++) {
        if (selects[k].parentNode.getElementsByTagName("span")[0]) {
            selects[k].onfocus = function() {
                this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
            }
            selects[k].onblur = function() {
                this.parentNode.getElementsByTagName("span")[0].style.display = "none";
            }
        }
    }
}
addLoadEvent(prepareInputsForHints);

我建议在这个问题中包含javascript函数,用于显示和隐藏工具提示和错误消息。然而,我的第一个想法是,您是针对您遇到的第一个标记,而不是按类名选择标记。我假设您正在使用javascript或javascript框架来实现这一点。有可能看到javascript代码吗?看起来可能有东西被弄错了,你应该能够有一个包含错误的div和另一个包含工具提示的div。从那里,您应该能够将它们设置为显示:无;默认情况下,然后在模糊上显示它们。添加了代码,但不应该是这样。是CSS影响了它的显示,虽然我可能错了。也许我会尝试将错误设置为div而不是span class error,看看效果是否更好。一开始我就注意到你的window.onload函数缺少一个分号。
.error {
    margin-left:5px;
    font-size:.75em;
    font-weight:bold;
    width:80px;
    color:#FF0000;
}

.hint {
    display:none;
    position:absolute;
    left:650px;
    width:200px;
    margin-top:-4px;
    border:1px solid #c93;
    padding:1.5px 10px 1.5px 10px;
        /* to fix IE6, I can't just declare a background-color,
        I must do a bg image, too!  So I'm duplicating the pointer.gif
        image, and positioning it so that it doesn't show up
        within the box */
    background:#ffc url(pointer.gif) no-repeat -10px 5px;
    font-weight: normal;
}

/* The pointer image is added by using another span */
.hint .hint-pointer {
    position:absolute;
    left:-10px;
    top:-1px;
    width:10px;
    height:19px;
    background: url(/_images/pointer.gif) left top no-repeat;
}