Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.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
Jquery 更改元素的HTML_Jquery_Toggle - Fatal编程技术网

Jquery 更改元素的HTML

Jquery 更改元素的HTML,jquery,toggle,Jquery,Toggle,你好,朋友,我被一个令人困惑的错误阻止了它看起来很简单,但我做不到我只想在点击ID时切换一个div,然后更改html()此ID与当前显示的Hide类似,当用户单击它时,它会显示“show”,但在我的代码中它不会出现,面板工作正常,切换效果请检查。请帮帮我 提前感谢……您让这件事变得比实际需要困难得多。我会这样做: $('#showhide').click(function(){ var div = $(this); $('.camera_discription_cont_text_con

你好,朋友,我被一个令人困惑的错误阻止了它看起来很简单,但我做不到我只想在点击
ID
时切换一个div,然后更改
html()
ID
与当前显示的
Hide
类似,当用户单击它时,它会显示“show”,但在我的代码中它不会出现,面板工作正常,切换效果请检查。请帮帮我
提前感谢……

您让这件事变得比实际需要困难得多。我会这样做:

$('#showhide').click(function(){
  var div = $(this);
  $('.camera_discription_cont_text_container').slideToggle('slow',function() {
      div.html($(this).is(":visible") ? "hide" : "show");
  });
})
但要真正解释代码的错误,您需要使用“elseif”而不是第二个“if”语句,例如:

$('#showhide').click(function(){

    if($(this).html()=='hide') {
        $(this).removeClass('hide');
        $(this).addClass('show');
        $(this).html('show');
    }
    else if($(this).html()=='show') {   //note the "else if", not "if"
        $(this).removeClass('show');
        $(this).addClass('hide');
        $(this).html('hide');
    }

    $('.camera_discription_cont_text_container').slideToggle('slow', function() {
        // Animation complete.
    });

})

如果在第一个
If
语句中,将html更改为“show”。然后语句结束,您会说“如果html是‘show’,请将其更改为hide”。于是它就变成了隐藏。换句话说,它正在从“隐藏”更改为“显示”再更改为“隐藏”。使用“else if”是您想要的。

。我会这样做:

$('#showhide').click(function(){
  var div = $(this);
  $('.camera_discription_cont_text_container').slideToggle('slow',function() {
      div.html($(this).is(":visible") ? "hide" : "show");
  });
})
但要真正解释代码的错误,您需要使用“elseif”而不是第二个“if”语句,例如:

$('#showhide').click(function(){

    if($(this).html()=='hide') {
        $(this).removeClass('hide');
        $(this).addClass('show');
        $(this).html('show');
    }
    else if($(this).html()=='show') {   //note the "else if", not "if"
        $(this).removeClass('show');
        $(this).addClass('hide');
        $(this).html('hide');
    }

    $('.camera_discription_cont_text_container').slideToggle('slow', function() {
        // Animation complete.
    });

})
如果在第一个
If
语句中,将html更改为“show”。然后语句结束,您会说“如果html是‘show’,请将其更改为hide”。于是它就变成了隐藏。换句话说,它正在从“隐藏”更改为“显示”再更改为“隐藏”。使用“else if”是你想要的