替换Div内容onclick [英] Replace Div Content onclick

查看:172
本文介绍了替换Div内容onclick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对jQuery一无所知,但想实现一些非常重要的东西。

I know nothing about jQuery but want to achieve something really important.

我想要一个按钮/链接来替换div内容,如果我按

I want to have a button/link that will replace the div content and if I press that button again so it will put the original content back in position.

推荐答案

这里有一种方法:

$ b HTML:

<div id="1">
    My Content 1
</div>

<div id="2" style="display:none;">
    My Dynamic Content
</div>
<button id="btnClick">Click me!</button>

jQuery:

$('#btnClick').on('click',function(){
    if($('#1').css('display')!='none'){
    $('#2').html('Here is my dynamic content').show().siblings('div').hide();
    }else if($('#2').css('display')!='none'){
        $('#1').show().siblings('div').hide();
    }
});



JsFiddle: $ b http://jsfiddle.net/ha6qp7w4/

http://jsfiddle.net/ha6qp7w4/4 < ---评论


JsFiddle:
http://jsfiddle.net/ha6qp7w4/
http://jsfiddle.net/ha6qp7w4/4 <--- Commented

这篇关于替换Div内容onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆