开发者社区> 问答> 正文

input如何根据文本自适应宽度

<input class="form-control" type="text" placeholder="input如何根据文本自适应长度" />

展开
收起
小旋风柴进 2016-05-27 11:13:43 3373 0
1 条回答
写回答
取消 提交回答
  • <html>
    <head>
    <script type="text/javascript" src="/jquery/jquery.js"></script>
    <script>
    function demo() {
    var testLength = document.getElementById('test').value.length
    $("#test").css('width', testLength*5 + 'px')
    }
    </script>
    <body>
    <input id="test" onkeypress="demo()" type="text"/>
    </body>
    </html>
    2019-07-17 19:17:26
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载