weixin_33725807 2012-08-08 08:07 采纳率: 0%
浏览 44

如何将CSS添加到jquery .html()?

我有如下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有关吗?

  • 写回答

2条回答 默认 最新

  • weixin_33670713 2012-08-08 08:13
    关注

    The CSS rules should apply to all elements on screen, not just the ones that were there when the page was first loaded. I would check the css selectors to make sure that they match the class name(, make sure you remembered the . before the class)

    评论

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用