JQuery添加隐藏的HTML元素 [英] JQuery Add Hidden HTML Elements
本文介绍了JQuery添加隐藏的HTML元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HTML:
< input type ='button'value ='显示图片'id ='add'> < div class ='input'style ='display:none;'>< img src =http://www.myimg.com/img.png>< / div>
JQUERY:
$(#add)。click(function(){
$(。input:hidden:first)。show()});
基本上,当我按下显示图片按钮时,隐藏的图片显示在下方。
现在我怎样才能做到这一点,如果我再次点击按钮,图像就会消失。而且它不断。 (clickbutton - > show image; clickbutton - > hide image; click button - > show image ...)
谢谢! 尝试切换: /rel =nofollow> Further reading
$(#add)。click(function ){
$(。input:first)。toggle();
});
HTML:
<input type='button' value='Show Picture' id='add'><div class='input'style='display: none;'><img src="http://www.myimg.com/img.png"></div>
JQUERY:
$("#add").click(function() {
$(".input:hidden:first").show() });
Basically when I press the Show Picture button, the hidden picture appears below. Now how can I make it so that if I click the button again, the image disappears. And it does so continuously. (clickbutton -> show image; clickbutton -> hide image; click button -> show image...)
Thanks!
解决方案
Try toggle : Further reading
$("#add").click(function() {
$(".input:first").toggle();
});
这篇关于JQuery添加隐藏的HTML元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文