如何在验证通过时执行javascript警报 [英] How to do javascript alert only when validation passes
问题描述
我有一个电子邮件文本框(必填字段)和一个按钮。我希望每当用户输入他的邮件ID并点击按钮时,就会出现一个JavaScript弹出窗口。
我的问题是当我点击按钮时,弹出窗口出现之前必填字段消息
我希望编写的JavaScript代码如果文本框为空则会显示请输入电子邮件ID验证消息,如果用户提供他的电子邮件ID,然后弹出窗口将出现;否则没有。
请帮帮我
这是我的文本框和按钮
I have an email textbox (required field) and a button. I want that whenever a user puts his mail id and clicks the button a JavaScript popup should appear.
My problem is when I click the button, that popup is appearing before the required-field msg.
I want JavaScript code written in a way that if textbox is empty then it will show a "please enter email id" validation message and if user gives his email id then that popup will appear; otherwise not.
pls help me out
this is my text box and button
<div class="input-append">
<input type="email" id="email" name="email" placeholder="Your Email" required>
<button class="subscribe-button btn" type="submit" onclick="myFunction()">SUBSCRIBE</button>
</div>
这是我的javascript代码< br $> b $ b
and this is my javascript code
<script type="text/javascript">
function myFunction() {
alert("You have done it");
}
</script>
推荐答案
这个例子怎么样
http://www.w3schools.com/js/tryit.asp?filename=tryjs_form_validation [ ^ ]
What about this example
http://www.w3schools.com/js/tryit.asp?filename=tryjs_form_validation[^]
这篇关于如何在验证通过时执行javascript警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!