gpt4 book ai didi

jquery - 将 css 添加到 jquery .html() 加载

转载 作者:太空宇宙 更新时间:2023-11-03 19:01:38 24 4
gpt4 key购买 nike

您好,我有一些可用的 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 文件中包含了这些跨度类的 css,但是当这个跨度被函数加载时,它看起来就像默认情况下一样。

我在另一个页面上遇到了类似的问题,我加载了一个搜索结果表,它只显示为默认值。我认为它与外部 CSS 引用有关?

最佳答案

CSS 规则应该适用于屏幕上的所有元素,而不仅仅是页面首次加载时存在的元素。我会检查 css 选择器以确保它们与类名匹配(确保你记得类之前的 .)

关于jquery - 将 css 添加到 jquery .html() 加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11860282/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com