【问题标题】:Javascript - How can we show popup-balloon with code?Javascript - 我们如何用代码显示弹出气球?
【发布时间】:2014-07-25 22:25:16
【问题描述】:

如果我们有这个代码

<form>
    <input required oninvalid="this.setCustomValidity('error messege')" />
    <input type="submit">
</form>

当我们单击提交按钮时,会显示包含错误消息文本的气球...

现在如果我们想触发这个气球来显示我们能做什么? 例如我们有这个 HTML 代码:

<input id="myTextBox" >
<input type="button" onclick="showBalloon()" >

<script>
    function showBalloon(){
        var elem = document.getElementById('myTextBox');
        elem.setCustomValidity('error messege');


        // my problem is HERE !!!
        elem.whichFunctionShouldICallOrWhatToDo(); // this shows balloon of myTextBox
    }
</script>

【问题讨论】:

  • 你是说工具提示?如果要自定义弹出窗口,则必须创建一个 div 并将其设置为 visibe,将文本放入其中并显示它。就目前而言,这个问题太宽泛了,这里提出了多个问题。一旦你尝试了一些东西但它不起作用,就给它一个真正的尝试并提出一个问题。
  • 不,我的意思是默认错误弹出气球...
  • 但是,感谢您的帮助

标签: javascript validation input textbox popup-balloons


【解决方案1】:

我认为您已经完成了主要功能,您只需要一个 HTML 元素,并修改样式以显示或隐藏。

<div id='myTextBox' style="display: none;"></div> 
// i'd set it in your javascript, but you get the idea

elem.innerHTML = 'error message';
elem.style.display = 'visible'; //show

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-15
    • 1970-01-01
    • 2010-10-29
    相关资源
    最近更新 更多