Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.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
该部门获胜';隐藏Javascript/HTML $(文档).ready(函数(){ $(“#隐藏”)。单击(函数(){ 美元(p).隐藏(500);; document.getElementById('show').innerHTML='Plaats een Feed»;'; }); $(“#显示”)。单击(函数(){ 元(p).show(500元);; document.getElementById('show').innerHTML='Afbreken(x)'; document.getElementById('show').id='hide'; }); });_Javascript_Jquery_Html - Fatal编程技术网

该部门获胜';隐藏Javascript/HTML $(文档).ready(函数(){ $(“#隐藏”)。单击(函数(){ 美元(p).隐藏(500);; document.getElementById('show').innerHTML='Plaats een Feed»;'; }); $(“#显示”)。单击(函数(){ 元(p).show(500元);; document.getElementById('show').innerHTML='Afbreken(x)'; document.getElementById('show').id='hide'; }); });

该部门获胜';隐藏Javascript/HTML $(文档).ready(函数(){ $(“#隐藏”)。单击(函数(){ 美元(p).隐藏(500);; document.getElementById('show').innerHTML='Plaats een Feed»;'; }); $(“#显示”)。单击(函数(){ 元(p).show(500元);; document.getElementById('show').innerHTML='Afbreken(x)'; document.getElementById('show').id='hide'; }); });,javascript,jquery,html,Javascript,Jquery,Html,div不会与上面的代码一起隐藏 我试图通过点击一个按钮来制作一个显示和隐藏div的脚本。按钮中的文本必须更改,这是有效的。如果你点击按钮,它将隐藏div。但是它不会发生。我不知道怎么修理它 如果要显示/隐藏多个元素,则不能使用ID。您将获得通过事件“this”单击的元素的引用 <script> $(document).ready(function(){ $("#hide").click(function(){ $("p").hide(500); document.

div不会与上面的代码一起隐藏


我试图通过点击一个按钮来制作一个显示和隐藏div的脚本。按钮中的文本必须更改,这是有效的。如果你点击按钮,它将隐藏div。但是它不会发生。我不知道怎么修理它

如果要显示/隐藏多个元素,则不能使用ID。您将获得通过事件“this”单击的元素的引用

<script>
$(document).ready(function(){
  $("#hide").click(function(){
    $("p").hide(500);
    document.getElementById('show').innerHTML = 'Plaats een Feed &#187;';
  });
  $("#show").click(function(){
    $("p").show(500);
    document.getElementById('show').innerHTML = 'Afbreken (x)';
    document.getElementById('show').id = 'hide';
  });
});
</script>

$(文档).ready(函数(){
$(“.hide”)。单击(函数(){
$(此).hide(500);
$(此).text('Plaats een Feed»;');
});
$(“.show”)。单击(函数(){
元(今次),显示(500元);;
$(this.text('Afbreken(x)');
$(this.removeClass('show');
$(this.addClass('hide');
});
});

正如您提到的,按钮的ID将动态变化,下面的代码将满足您的需要。检查演示并确认这是否是您想要的:

<script>
$(document).ready(function(){
  $(".hide").click(function(){
    $(this).hide(500);
    $(this).text('Plaats een Feed &#187;');
  });
  $(".show").click(function(){
    $(this).show(500);
    $(this).text('Afbreken (x)');
    $(this).removeClass('show');
    $(this).addClass('hide');
  });
});
</script>
HTML我根据这个问题假设:

$(document).ready(function(){
  $(document).on('click', "#hide", function(){
    $("#divId").hide(500);  // considering you have div with id divID
    $(this).text( 'Plaats een Feed &#187;');
    this.id = 'show';
  });
  $(document).on('click',"#show", function(){
    $("#divId").show(500);  // considering you have div with id divID
    $(this).text('Afbreken (x)');
    this.id = 'hide';
  });
});

p标签中的一些内容
隐藏

如果需要,只需将
样式
可见性
隐藏
高度
宽度
设置为
0

因为您隐藏了“p”即段落。标记中的第一段将被隐藏。如果div是
,那么您的代码应该是
$(这个)。hide(500)
@RahulPatil实际上文档中的所有
块都将被隐藏,而不仅仅是第一个。如果要使用jQuery,那么就使用jQuery。使用
$('#show').html('Afbreken(x)')
代替
document.getElementById('show')。innerHTML='Afbreken(x)'<div id="divId">
   Some content in p tag
</div>


<button id="hide" value="hide">Hide</button>