繁体   English   中英

仅在完成函数A,B和C之后如何调用函数D

[英]How to call function D only after function A, B and C are done

嗨,大家好,我想知道是否只有在函数checkV,checkV1,checkV2完成并且填写完整后,才可以调用函数“ confirm”。

HTML和JavaScript

http://pastebin.com/xY1MBhv5

 function checkV() { var check = document.getElementById("voornaam").value; if (isNaN(check) || check.length == 0) { return true; } else { alert("In de naamvelden geen cijfers invoeren svp"); } }; function checkV1() { var check1 = document.getElementById("achternaam").value; if (isNaN(check1) || check1.length == 0) { return true; } else { alert("In de naamvelden geen cijfers invoeren svp"); } }; function checkV2() { var check2 = document.getElementById("toneelspeler").value; if (isNaN(check2) || check2.length == 0) { return true; } else { alert("In de naamvelden geen cijfers invoeren svp"); } }; function confirm() { var voorNaam = document.getElementById("voornaam").value; var toneelNaam = document.getElementById("toneelspeler").value; var achterNaam = document.getElementById("achternaam").value; alert("Beste " + voorNaam + " " + achterNaam + ", ontzettend bedankt voor je wens, we zullen ervoor zorgen dat " + toneelNaam + " je wens zal ontvangen!"); }; window.onload = function() { document.getElementById('submit').onclick = function() { checkV() checkV1() checkV2() confirm() }; }; 
 <header> <div id="logo"> <a href="home.html"> <img src="logo.png" id="home" alt="Logo van Het Imperium Theater"> </a> <a href="http://www.facebook.com" target="blank"> <img src="facebook.png" id="facebook" alt="facebook" /> </a> <a href="http://www.twitter.com" target="blank"> <img src="twitter.png" id="twitter" alt="twitter" /> </a> </div> <nav> <ul> <li><a href="Home.html">Home</a> </li> <li><a href="Agenda.html">Agenda</a> </li> <li><a href="Het Theater.html">Het Theater</a> </li> <li><a href="Ontdek Leiden.html">Ontdek Leiden</a> </li> <li><a href="Contact.html">Contact</a> </li> </ul> </nav> </header> <div id="wrapper"> <form id="form" name="form"> <h1>Verstuur een wens.</h1> <div id="forms"> <label for="voornaam">Voornaam: <input type="text" name="name" id="voornaam" placeholder="uw voornaam" name="fname" required> </label> <label for="achternaam">Achternaam: <input type="text" name="name" id="achternaam" placeholder="uw achternaam" name="fname" required> </label> <label for="toneelspeler">Naam toneelspeler: <input type="text" name="name" id="toneelspeler" placeholder="naam van de toneelspeler" name="fname" required> </label> <label for="boodschap">Uw wens: <textarea rows="4" cols="20" name="name" placeholder="Type hier uw wens" required></textarea> </label> </div> <input type="submit" value="Submit" id="submit"> </form> </div> <footer> <a href="home.html"> <p>Theater Imperium</p> </a> <p>Oude Vest 33e</p> <p>2312 XR Leiden</p> <p>071 5141035</p> <p>&copy; Arpiar Melikjan</p> </footer> 

根据提供的链接,如果一切正常, checkV(), checkV1()checkV2()将返回true ,否则返回undefined 您可以执行以下操作:

if(checkV() && checkV1() && checkV2())
    //Do submit

编辑:

如果要对控制流进行更多控制(这可能有助于调试),则可以执行以下操作:

if(checkV()) {
    if(checkV1()) {
        if(checkV2()) {
            //Do submit
        }
    }
}

现在,您可以关联else块,并可以根据未能验证输入的方法采取措施。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM