简体   繁体   中英

How to print some javascript code on html page

 <html><body> <p id="demo"></p> <script> function validato() { document.getElementById("demo").innerHTML = emailio; } function emalio(x,y){ function ValidateEmail(mail) { if (/^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,3})+$/.test(myForm.emailAddr.value)) { return (true) } alert("You have entered an invalid email address!") return (false) } } </script> </body></html> 

I tried to print function imalio() as it is on html page by not giving parameter. but it is not doing anything. Please somebody explain it to me.

Quentin is right. You have not called your function.

Add validato() to call your function and it will print the contents of the other function in your HTML element.

 <html> <body> <p id="demo"></p> <script> function validato() { document.getElementById("demo").innerHTML = foo; } function foo(x, y) { function bar(z) { return (false); } } validato(); </script> </body> </html> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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