[Angular HTML] Overwrite input value, String.fromCharCode & input.selectionStart
- @HostListener('keydown', ['$event', '$event.keyCode'])
- onKeyDown($event: KeyboardEvent, keyCode) {
- if(keyCode !== TAB) {
- $event.preventDefault();
- }
- // get value for the key
- const val = String.fromCharCode(keyCode);
- // get position
- const cursorPos = this.input.selectionStart;
- overWriteCharAtPosition(this.input, val, cursorPos);
- }
- export const overWriteCharAtPosition = (
- input: HTMLInputElement,
- val: any,
- position: number
- ) => {
- const currentValue = input.value;
- input.value = currentValue.slice(, position) + val + currentValue.slice(position+);
- };
[Angular HTML] Overwrite input value, String.fromCharCode & input.selectionStart的更多相关文章
- Android input输入框 移动页面input手机键盘中的“搜索”按键
动页面input手机键盘中的“搜索”按键 满足以下几点机即可: input type="search" 放到form标签中 使用action属性 <form ac ...
- 封装input 逐渐,且input插件必须带有默认值。
封装input 逐渐,且input插件必须带有默认值. 组件: <template> <div class="input-show"> <span c ...
- 数组乘积--满足result[i] = input数组中除了input[i]之外所有数的乘积(假设不会溢出
数组乘积(15分) 输入:一个长度为n的整数数组input 输出:一个长度为n的整数数组result,满足result[i] = input数组中除了input[i]之外所有数的乘积(假设不会溢出). ...
- Oracle delete input与delete all input
oracle官方文档提示:If you had specified DELETE INPUT rather than DELETE ALL INPUT, then RMAN would have on ...
- input type类型和input表单属性
一.input type类型 1.Input 类型 - email 在提交表单时,会自动验证 email 域的值. E-mail: <input type="email" n ...
- 定制 input[type="radio"] 和 input[type="checkbox"] 样式
表单中,经常会使用到单选按钮和复选框,但是,input[type="radio"] 和 input[type="checkbox"] 的默认样式在不同的浏览器或 ...
- 修改 input[type="radio"] 和 input[type="checkbox"] 的默认样式
表单中,经常会使用到单选按钮和复选框,但是,input[type="radio"] 和 input[type="checkbox"] 的默认样式在不同的浏览器或 ...
- angular自定义指令解决IE89不支持input的placeholder属性
下面代码实测通过,直接copy到本地运行即可. <!DOCTYPE html> <html> <head> <meta charset="UTF-8 ...
- How to Construct the Input Bet String
The purpose of this section is to describe the format of the string which will submitted to the Pyth ...
随机推荐
- logout命令用于退出当前登录的Shell
logout命令用于退出当前登录的Shell
- nice---进程优先级
在当前程序运行优先级基础之上调整指定值得到新的程序运行优先级,用新的程序运行优先级运行命令行"command [arguments...]".优先级的范围为-20 - 19 等40 ...
- 基于 Cookie 的 SSO 中间件 kisso
kisso = cookie sso 基于 Cookie 的 SSO 中间件,它是一把快速开发 java Web 登录系统(SSO)的瑞士军刀.欢迎大家使用 kisso !! kisso 帮助文档 ...
- error c2572重定义默认參数
因为想省事.在声明过函数之后直接复制粘贴去实现,结果出现error c2572重定义默认參数 顾名思义.该默认參数被定义多次.在一个文件(或一个作用域)中,仅仅能为形參指定默认 实參一次.在编译的时候 ...
- Oracle11gR2 Windows 7 64bit and PL/SQL Developer排错
1.Environment variable: "PATH" - This test checks whether the length of the environment va ...
- git 工具的使用总结(5)-查看历史记录
1.查看历史记录git log 1)不加参数,显示的就是节点号,作者,日期,注释 commit b7b310d220628530d1feb9e8046ccb59039d59f2 Author: zha ...
- 三、Docker镜像的相关操作
原文:三.Docker镜像的相关操作 一.查看本地镜像: docker images 二.使用某个镜像来运行容器: docker run -t -i xxxx(镜像名):xx.xx(版本,不带即最新) ...
- HUSTOJ 1072 小数背包问题
HUSTOJ 1072 小数背包问题 题目描述 有一个背包,背包容量是M(0<M≤500),有N(1<N≤1000)个物品,物品可以分割成任意大小. 要求尽可能让装入背包中的物品总价值最大 ...
- 【2017"百度之星"程序设计大赛 - 复赛】Arithmetic of Bomb
[链接]http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=777&pid=1001 [题意] 在这里写 [题解] ...
- TextView-shadow 阴影实现
直接上代码 1)实现普通效果 <TextView android:layout_width="match_parent" android:layout_height=&quo ...