[英]Javascript - How can we show popup-balloon with code?
如果我們有這個代碼
<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>
我認為您已經失去了主要功能,只需要一個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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.