简体   繁体   English

Javascript无法在WAMP上运行,但如果没有WAMP,则可以正常运行

[英]Javascript doesn't work on WAMP but works fine without it

I just started learning PHP and WAMP. 我刚刚开始学习PHP和WAMP。 Before that I created a set of webpages using HTML,CSS, and JS. 在此之前,我使用HTML,CSS和JS创建了一组网页。 The JS is for validating the form, and if everything goes well it will jump to a php page that insert data into sql database. JS用于验证表单,如果一切顺利,它将跳转到将数据插入sql数据库的php页面。

The simplified form.html and validation.js are: 简化的form.html和validation.js是:

function validation() {
  var emailCheck = email.search(/^[a-zA-z0-9_]+\@[a-zA-z0-9_]+\.[a-zA-z]{2,3}$/);
  if (emailCheck==-1) alert("Please enter a valid email address");
  else document.getElementById("signup").action = "success.php";
 }

The Form code 表格代码

<form id="signup" class = "signup" method="POST">
  .....
<input type="text" name="email" id="email" required/>
  ....
<button class = "button3" onclick = "validation()">Submit</button>
</form>

The success.php is simply to insert data to the mySQL database. success.php只是将数据插入到mySQL数据库中。

Now I run the form.html without using the localhost, the javascript works perfectly. 现在,我在不使用localhost的情况下运行form.html,javascript可以完美运行。 The alert window shows up if I enter wrong stuff. 如果我输入错误的内容,将显示警报窗口。

If I run localhost/form.html with WAMP, when I enter wrong stuffs, the javascript doesn't work. 如果我使用WAMP运行localhost / form.html,则当我输入错误的内容时,javascript无法正常工作。 The alert window doesn't show up. 警报窗口不显示。 BUT when I pass the validation, it successfully jumps to the success.php. 但是,当我通过验证时,它会成功跳转到success.php。

Therefore, I consider the Javascript is working but somehow part of it doesn't since the javascript is the only connection between the form.html and success.php. 因此,我认为Javascript可以正常工作,但由于JavaScript是form.html和success.php之间的唯一连接,因此部分原因无法正常工作。

Any idea? 任何想法?

variable "email" is undefined, so you can't using search function on a undefined variable. 变量“电子邮件”是未定义的,因此您不能对未定义的变量使用搜索功能。 You need get the email value first. 您需要首先获取电子邮件值。

function validation() {
    var emailCheck = document.getElementById("email").value.search(/^[a-zA-z0-9_]+\@[a-zA-z0-9_]+\.[a-zA-z]{2,3}$/);
    if (emailCheck==-1) alert("Please enter a valid email address");
    else document.getElementById("signup").action = "success.php";
}

暂无
暂无

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

相关问题 javascript中的click()无法正常运行,但在控制台中可以正常运行 - click() in javascript doesn't work but in console it works fine Javascript在IE中不起作用,在其他所有方面都可以正常工作 - Javascript doesn't work in IE, works fine in everything else 为什么 Jquery $(#); 不工作,但 Javascript document.getElementById 工作正常吗? - Why Jquery $(#); doesn't work but Javascript document.getElementById works fine? Javascript问题,使用localhost可以正常运行网站,使用computername不能正常工作 - Javascript issue, site works fine using localhost, doesn't work using computername JavaScript函数在Opera中工作正常,但在Firefox中根本不工作。 为什么? - JavaScript function works fine in Opera but doesn't work at all in Firefox. Why? 在IE 9之前无法使用的Javascript / jquery代码在FF,Chrome,Safari中正常运行 - Javascript/jquery code that doesn't work prior to IE 9. Works fine in FF, Chrome, Safari WebDriverIO 6 – $ 工作正常,$ 在 iframe 中不起作用 - WebDriverIO 6 &ndash; $ works fine, $ doesn't work in iframe 为什么这个 function 在 Safari 中不起作用? (在 Chrome 中工作正常) - Why doesn't this function work in Safari? (works fine in Chrome) heroku 本地 web 工作正常但部署不正常 - heroku local web works fine but deployment doesn't work properly 全局替换不起作用,但是简单替换可以正常工作 - global replace doesn't work , but simple replace works fine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM