toggle 方法的使用

<!DOCTYPE html>
<html>
<head>
    <title></title>
<style type="text/css">
.tp-user-biming {
    position: relative;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}
.tp-user-biming .fds {
    padding-right: .25rem;
}
.tp-user-biming input {
    height: 25px;
    outline: none;
    border: 1px solid #e5e0e0;
    box-sizing: border-box;
    width: 35%;
    background: #f6f5f5;
    padding: 0 .25rem;
    margin-right: .25rem;
}
.icon-biming {
    height: 20px;
    width: 20px;
    background: url(../img/f5.png) no-repeat;
    margin: 2px 0;
    display: block;
}
</style>
    <script src="jquery.js"></script>
</head>
<body>
<div class="tp-user-biming">
    <span id="biming"></span>
    <i class="icon-biming" id="icon-biming"></i>
</div>

<script>
    $(document).ready(function(){
        
        $(".icon-biming").toggle(
        function() {
            var bm = $('#biming');
            var str = bm.text();
            bm.replaceWith("<input type='text' placeholder='笔名' id='inputValue' value='"+str+"' />");               
        },
        function() {
            var iValue = $('#inputValue');
            var istr = iValue.val();
            iValue.replaceWith("<span id='biming' class='fds'>"+istr+"</span>");
        }
      );
    });
</script>
</body>
</html>

注:toggle() 方法在 jQuery 版本 1.8 中被废弃,在版本 1.9 中被移除。

转载于:https://www.cnblogs.com/quietxin/p/9242619.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值