点击提交按钮上的onclick事件 [英] onclick event on submit button
问题描述
我试图在点击提交按钮并调用js函数后验证输入文本是否具有电子邮件格式。我遇到的第一个问题是,经过一些测试后,我发现它没有进入被调用的函数。在此之后,我认为一切都应该没问题,但为了万一为了不在几分钟之内发布2个几乎相同的问题,就不应该包含最重要的部分。
总结一下,它应该检查:
- 电子邮件字段不为空
- 电子邮件字段有@(不考虑订单等)
然后它应该告诉它是否发现任何问题,如果不是所有情况都不变,那么
我希望我提出了我的观点,如果不是我可以尝试解释它
< input type =textname =emailid =email>
< input type =submitonclick =proceed()/>
< script>
proceed(){
var email = document.getElementById('email')。value;
var问题;
if(email ==){
problems =空变量\\\
;
}
var noat = true;
for(int i = 0; email.length; i ++){
if(email.charAt(i)==@){//比较每个字符
noat = false;
休息;
if(email ==|| noat = true){
problems + =No @ \\\
警报(问题);
}
}
< / script>
< form onsubmit =return proceed();>
< input type =textname =emailid =email>
< input type =submit/>
< / form>
< script>
函数proceed(){
var email = document.getElementById('email')。value;
var problems =;
if(email ==){
problems =空变量\\\
;
}
var noat = false;
if(email.indexOf(@)== -1)noat = true;
// for(int i = 0; i< email.length; i ++){
// if(email.charAt(i)==@){//比较每个字符
// noat = false;
// break;
//
if(email ==|| noat == true){
problems + =No @ \\\
;
警报(问题);
}
if(problems ==)
return true;
else
返回false;
}
< / script>
I'm trying to make a verification that an input text has an email format after clicking submit buttom and calling a js function. The first problem i encounter is that after some tests, i've seen that it doesnt enter the called function. After this, i think everything should be ok, but just in case in order to not post 2 almost equal questions within minutes, ill include the most important part. Summarizing, it should check: -The email field is not null -The email field has an @ (without taking into account order etc)
Then it should tell if it found any problem, if not leave everything unchanged
I hope i made my point, if not i can try to explain it again..
<input type="text" name="email" id="email">
<input type="submit" onclick=" proceed()"/>
<script>
proceed(){
var email= document.getElementById('email').value;
var problems;
if (email == ""){
problems = "Empty variable \n";
}
var noat = true;
for (int i=0; email.length; i++){
if (email.charAt(i) == "@"){ //Compare each character
noat=false;
break;
}
}
if (email=="" || noat=true){
problems += "No @ \n"
alert(problems);
}
}
</script>
<form onsubmit="return proceed();">
<input type="text" name="email" id="email">
<input type="submit" />
</form>
<script>
function proceed() {
var email = document.getElementById('email').value;
var problems = "";
if (email == "") {
problems = "Empty variable \n";
}
var noat = false;
if (email.indexOf("@") == -1) noat = true;
// for (int i=0; i< email.length; i++){
// if (email.charAt(i) == "@"){ //Compare each character
// noat=false;
// break;
//}
if (email == "" || noat == true) {
problems += "No @ \n";
alert(problems);
}
if (problems == "")
return true;
else
return false;
}
</script>
这篇关于点击提交按钮上的onclick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!