我希望有人能帮助我的项目学校。我有这样一段HTML代码:我的Javascript不能在localhost工作XAMPP
<!DOCTYPE html>
<html>
<head>
<title>Tambah Guru</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css"/>
<script type='text/javascript' src='script.js' charset="utf-8"></script>
</head>
<body>
Email: <input type='text' id='txtemail' />
<input type='submit' value='Simpan' id='validateemail' />
</body>
</html>
然后我的JavaScript代码:
$(document).ready(function(e) {
$('#validateemail').click(function() {
var sEmail = $('#txtemail').val();
if ($.trim(sEmail).length == 0) {
alert('Please enter valid email address');
e.preventDefault();
}
if (validateEmail(sEmail)) {
alert('Email is valid');
} else {
alert('Invalid Email Address');
e.preventDefault();
}
});
});
function validateEmail(sEmail) {
var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (filter.test(sEmail)) {
return true;
} else {
return false;
}
}
当我运行它
,这是行不通的。我不知道为什么。有人可以帮我吗?
哪部分*不起作用*? – Joseph
对于一个他不包括jquery。 – 2013-05-19 05:12:38
按照[jQuery.com的说明](http://learn.jquery.com/about-jquery/how-jquery-works/)在您的页面上添加jquery.js。如果仍不起作用,请澄清“不工作”的含义:指定所需的行为和实际行为。 – nnnnnn