Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP和jQuery显示:无_Php_Jquery_Html - Fatal编程技术网

PHP和jQuery显示:无

PHP和jQuery显示:无,php,jquery,html,Php,Jquery,Html,当用户名字段为空时,我试图使用jQuery显示错误文本。这不是问题,因为我已经这样做了。问题是,在显示错误文本后,我想单击username字段并隐藏错误文本div,这样,如果字段仍然为空,我就可以使用jQuery重新显示错误 当我使用jQuery将可见性设置为隐藏在CSS中时,当我在Google Chrome的inspector中查看代码时,它会自动添加一个display:hidden 代码位于: 执行.css('display','none')和.css('display','block')隐

当用户名字段为空时,我试图使用jQuery显示错误文本。这不是问题,因为我已经这样做了。问题是,在显示错误文本后,我想单击username字段并隐藏错误文本div,这样,如果字段仍然为空,我就可以使用jQuery重新显示错误

当我使用jQuery将可见性设置为隐藏在CSS中时,当我在Google Chrome的inspector中查看代码时,它会自动添加一个
display:hidden

代码位于:

执行
.css('display','none')
.css('display','block')
隐藏/显示应该可以正常工作

另一种方法是设置
.html(“”)
从div中删除文本(从而使其隐藏)。这样您就不必担心div的可见性了。

试试看

$('#error1').fadeOut('fast', function () {
   $(this).show()
   $(this).css("visibility","hidden")    
})

因为淡出设置显示:无;你也在使用visibility属性,去掉visibility,改用.show()和.hide()

我实际上在尝试下面的代码,我甚至在尝试$(this).css(“display”,“inline”),但它仍然不起作用。请查看我的网站了解更多详细信息div标签是一个“block”元素,而不是一个“inline”元素,因此,要使其可见,您应该执行display:'block'和display:'none'来隐藏它。通过将div设置为“inline”,基本上就是将其转换为span标记。请看下面我的答案。谢谢你的回答,但我认为这不会奏效,因为我需要#error1=可见性:隐藏;为什么需要使用“可见性”?我同意,jquery将其转换为“display”是一种奇怪的行为,但将文本设置为空白(并且根本不担心可见性)这似乎是一个更简单的解决方案,可以让你删除一些不需要的代码。我需要使用visibility=hidden,因为如果我在单击登录时不这样做,并且如果我第二次留下一个空白字段,那么可见性将是可见的,如果它没有显示,我会很好:没有,它会自动添加,请在我的网站上点击和源代码,如果可以的话,在单击“登录”和“用户名”字段之前和之后,我想说的是,您不需要设置任何可见性。一点也不要藏起来。如果要通过调用.html(“”);,将div中的文本隐藏,只需将其设置为空白即可;。谢谢你的帮助,但超新星的回答纠正了我的问题。。无论如何,谢谢你花时间看我的代码。。祝你有一个愉快的一天非常感谢你我感谢大家的帮助。。祝你有美好的一天。。如果答案解决了您的问题,请将其标记为已接受,然后重新编写代码,不要使用可见属性:P
$(document).ready(function(){

    $('.form').submit(function(e) {
        register();
        e.preventDefault();
    });

    $('.login_form').submit(function(e) {
        login();
        e.preventDefault();
    });

});

function register(){
    hideshow('loading',1);
    error(0);

    $.ajax({
        type: "POST",
        url: "php/register.php",
        data: $('.form').serialize(),
        dataType: "json",
        success: function(msg){
            if(parseInt(msg.status)==1){
                window.location=msg.txt;
            } else if(parseInt(msg.status)==0) {
                error(1,msg.txt);
            }
            hideshow('loading',0);
        }
    });
}

function login(){
    hideshow1('loading1',1);
    error1(0);

    $.ajax({
        type: "POST",
        url: "php/login.php",
        data: $('.login_form').serialize(),
        dataType: "json",
        success: function(msg1){
            if(parseInt(msg1.status1)==1){
                window.location=msg1.txt1;
            } else if (parseInt(msg1.status1) == 0) {
                error1(1,msg1.txt1);
            }
            hideshow1('loading1',0)
        }
    });
}
function hideshow(el,act){
    if(act) $('#'+el).css('visibility','visible');
    else $('#'+el).css('visibility','hidden');
}
function error(act,txt){
    hideshow('error',act);
    if(txt) $('#error').html(txt);
}
function hideshow1(el,act){
    if(act) $('#'+el).css('visibility','visible');
    else $('#'+el).css('visibility','hidden');
}
function error1(act,txt1){
    hideshow1('error1',act);
    if(txt1) $('#error1').html(txt1);
}
$('#error1').fadeOut('fast', function () {
   $(this).show()
   $(this).css("visibility","hidden")    
})