嗨,我有一些工作 jquery 代码是:
$(document).ready(function()
{
$("#createaccount").submit(function(e){
var fname = $("#fname").val();
var surname = $("#surname").val();
var email = $("#email").val();
var location = $("#location").val();
var username = $("#username").val();
var password = $("#password").val();
var re_pass = $("#re_password").val();
var valid = true;
if(fname == ""){
$("#fnameerror").html('<span class="errortext">Please enter your first name</span>');
valid = false;
}
if(surname == ""){
$("#surnameerror").html('<span class="errortext">Please enter your surname</span>');
valid = false;
}
if(email == ""){
$("#emailerror").html('<span class="errortext">Please enter an email address</span>');
valid = false;
}
else{
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if(reg.test(email)==false){
$("#emailerror").html('<span class="errortext">The email address is invalid</span>');
valid = false;
}
}
if(location == ""){
$("#locationerror").html('<span class="errortext">Please enter your location</span>');
valid = false;
}
if(username == ""){
$("#usernameerror").html('<span class="errortext">Please enter a username</span>');
valid = false;
}
else{
if(username.length < 6){
$("#usernameerror").html('<span class="errortext">Username must be at least 6 characters long</span>');
valid = false;
}
}
if(password == ""){
$("#passworderror").html('<span class="errortext">Please enter a password</span>');
valid = false;
}
else{
if(password.length < 6){
$("#passworderror").html('<span class="errortext">Password must be at least 6 characters long</span>');
valid = false;
}
}
if(re_pass == ""){
$("#re_passerror").html('<span class="errortext">Please re-enter your password</span>');
valid = false;
}
else{
if(re_pass != password){
$("#re_passerror").html('<span class="errortext">The passwords do not match</span>');
valid = false;
}
}
if(valid == false){
return false;
}
else{
$.ajax({
type: 'POST',
url: 'createaccount2.php',
data: $("#createaccount").serialize(),
success: function(response){
if(response == "1"){
$("#response").html('<span class="responsefail">Your username has already been taken, please enter another</span>');
}
else if(response == "2"){
$("#response").html('<span class="responsefail">An account is already registered to that email</span>');
}
else if(response == "3"){
$("#response").html('<span class="responsegood">Your account has been created!</span>');
$("#redirect").html('<span class="redirect">Click</span><a class="redirectlink" href="divbayindex.htm">HERE</a><span class="redirect"> to return to the DiveBay homepage</span>');
}
else if(response == "4"){
$("#response").html('<span class="responsefail">Something went wrong, your account could not be created, please try again in a moment</span>');
$("#redirect").html('<span class="redirect">Click</span><a class="redirectlink" href="divbayindex.htm">HERE</a><span class="redirect"> to return to the DiveBay homepage</span>');
}
}
});
e.preventDefault();
}
});
});
我只是想知道如何为这个跨度添加样式。我在原始页面的 css 文件中包含了这些 span 类的 css,但是当这个 span 被函数加载时,它会显示为默认值。
我在加载搜索结果表的另一个页面上遇到了类似的问题,它只显示为默认值。我认为它与外部 css 参考有关?