input框随输入的文字的多少自动调整宽度粗略版本
<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<style>
#demo {
padding: 0;
border: 0;
color: rgba(40, 99, 243, 1);
background-color: transparent;
border-bottom: 1px solid #333;
width: 90px;
-webkit-appearance: textfield;
-webkit-writing-mode: horizontal-tb !important;
-webkit-rtl-ordering: logical;
text-rendering: auto;
display: inline-block;
overflow: visible;
outline: none;
font-family: 微软雅黑;
font-size: 14px;
text-align: center;
}
</style> <body>
<input id="demo" type="text">
</body>
<script>
var demo = document.getElementById('demo')
demo.addEventListener('input', function () { var n = document.createElement('span');
n.style.display = "inline-block"
n.style.whiteSpace = "pre"
n.style.maxWidth = "100%"
n.style.fontSize = "14px"
n.style.fontFamily = "微软雅黑"
n.innerHTML = demo.value;
demo.parentNode.insertBefore(n, demo.nextSibling);
var spanW = n.getBoundingClientRect().width;
demo.parentNode.removeChild(n) demo.style.width = spanW + 'px' })
</script> </html>
input框随输入的文字的多少自动调整宽度粗略版本的更多相关文章
- 函数式组件中实现Antd打开Modal后其Input框自动聚焦(focus)到文字的最后
目前React使用函数式组件已经成为趋势, 如何把React函数式组件用好, 提高性能, 从而实现业务需求也成为了一种能力的体现......咳咳咳, 进入正题: 现实场景需求 我想实现这一个需求, 父 ...
- js—input框中输入数字,动态生成内容的方法
项目中需要在前端实现: 用户输入数字n,动态生成n个元素,删除n,自动清空n个元素(如图一): 用户输入数字n,失焦生成n个元素,再聚焦修改n,自动清空n个元素(如图二): 图一: 图二: 需求一实现 ...
- input框限制输入金额
HTML: <input type="tel" class="capital mui-input-clear" value="0.00" ...
- JS 限制input框的输入字数,并提示可输入字数
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 使用正则限制input框只能输入数字/英文/中文等等
常用HTML正则表达式 1.只能输入数字和英文的: 复制代码代码如下: <input onkeyup="value=value.replace(/[/W]/g,'') " o ...
- input框的输入限制
1.输入数字 <input onKeyUp="value=value.replace(/[^\d|chun]/g,'')"> 2.只输入中文 <input typ ...
- 使用UIkit的uk-form-icon后input框无法输入的问题
相关版本UIkit2.27.5 uikit.min.css默认使用uk-form-icon的属性pointer-events: none:因此表框无法点击. <style type=text/c ...
- javascript判断input框只能输入数字的方法
javascript 只允许输入数字有很多方法,总结如下 1,只允许输入数字和小数点. <input onKeypress="return (/[\d.]/.test(String.f ...
- js控制input框只能输入数字和一位小数点和小数点后面两位小数
<script language="JavaScript" type="text/javascript"> function clearNoNum( ...
随机推荐
- u盘使用记录、痕迹删除技巧方法
在日常生活的使用U盘过程当中,系统会记录下大量U盘的使用记录信息,那么接下来小编就来同大家分享介绍如何删除掉这些使用记录的方法知识. 1. 往系统里面添加环境变量devmgr_shownonprese ...
- leetcode746 Min Cost Climbing Stairs
""" On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 inde ...
- leetcode1042 Flower Planting With No Adjacent
""" You have N gardens, labelled 1 to N. In each garden, you want to plant one of 4 t ...
- kali下的截图工具scrot、flameshot和deepin-scrot
对于这几个截图工具,精简好用的应该是deepin-scrot了,这是个和QQ截图有类似功能的Linux截图工具.flameshot的功能是最多的,也很好用,虽然有的功能用不上. 1.scrot安装和使 ...
- 适配器之SimpleAdapter
前言: 在写适配器时,SimpleAdapter会经常使用到,虽然他比ArrayAdapter复杂,但是也提供了更多的功能 正文: 我们接下来先从SimpleAdapter中较为简单的显示两行文本开始 ...
- 6 —— node —— 响应一个完整的页面
const http = require('http'); const fs = require('fs'); const server = http.createServer(); server ...
- 无法启动APK安装也,报异常FileUriExposedException
无法打开APK安装页,报异常FileUriExposedException, https://juejin.im/entry/58e4643db123db15eb79a902
- 在Centos安装redis-孙志奇
最近在阿里云服务器上部署redis,遇到了很多的问题,经过不懈的努力终于配置成功, 按照下面的步骤一步一步来就好了 wget http://download.redis.io/releases/red ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-bookmark
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- js 混合构造原型 运用
1.给10个div添加点击事件 <body> <div class="sd">sdss</div> <div class="sd ...