爱编程的设计师 2023-04-01 20:58 采纳率: 94.4%
浏览 11
已结题

js只是改变了span的宽度,为什么文字颜色和line-height也改变了


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .home{
            width: 800px;
            height: 300px;
        }
        textarea{
            width: 500px;
            height: 30px;
            resize: none;
            box-sizing: border-box;
        }
        .father{
            width: 500px;
            height: 35px;
            border-radius: 5px;
            border: 1px solid rgb(6, 6, 112);
        }
        .son{
            /* float: left; */
            border-radius:5px 0px 0px 5px ;
            width: 50px;
            height:35px ;
            background-color: rgb(87, 87, 250);
            text-align: center;
            
        }
        .home .father .son span{
            line-height: 35px;
            color: white;
        }

    </style>
</head>
<body>
    <div class="home">
        <textarea name="" id="" cols="30" rows="10"></textarea>
        <div class="father">
            <div class="son">
                <span>10%</span>
            </div>
        </div>
    </div>
    <script>
        let ip = document.querySelector('textarea')
            father = document.querySelector('.father')
            son = document.querySelector('.son')
            tex = document.querySelector('span')
        ip.addEventListener('input',function(){
            son.style.transition = '0.6s'
            son.style.width = `${ip.value*5}px`
            son.innerText = `${ip.value}%`
        })
        
    </script>
</body>
</html>
  • 写回答

2条回答 默认 最新

  • 文盲老顾 WEB应用领新星创作者 2023-04-01 22:49
    关注

    因为你把 span 干掉了

    // son.innerText 改成下边这个
    son.innerHTML = `<span>${ip.value}%</span>`
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月23日
  • 已采纳回答 4月15日
  • 创建了问题 4月1日

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c