当前位置:网站首页>easyui中textbox在光标位置插入内容
easyui中textbox在光标位置插入内容
2022-07-27 01:47:00 【初生的太阳丶】
<input id="fileName" name="filename" class="easyui-textbox lg_width" data-options="tipPosition:'bottom'" type="text" >
title = "${aaa}";//要插入的内容
insertLabelText("fileName",title);//调用方法,fileName为id="fileName"的input标签
function insertLabelText(destobj,labelText) {
let lastIndex = getCursortPosition(destobj);//获取光标位置
let oldText = $('#'+destobj).textbox('getValue');//获取输入框的值
let newText = buildNewText(oldText, labelText, lastIndex);//把输入框的值与要插入的值拼接起来
$('#'+destobj).textbox('setValue',newText);//把拼接后的值设置到输入框
}
//获取光标位置
function getCursortPosition(destobj) {
var cursorIndex = "-1";
var obj = $('#'+destobj).next()[0].children[0]; //easyui生成的控件,输入的信息都是在这上面
if (document.selection) {
//IE浏览器
obj.focus ();
var range= document.selection.createRange();
range.moveStart ('character', -obj.value.length);
cursorIndex= range.text.length;
}else if (obj.selectionStart || obj.selectionStart==0) {
//非IE浏览器
cursorIndex= obj.selectionStart;
}
return cursorIndex;
}
//拼接新字符串
function buildNewText(oldText,labelText,lastIndex){
let newText = oldText.substring(0, lastIndex) + labelText;//插入在开始和结束的位置
if(oldText.length!=lastIndex&&oldText.length!=0){
//插入在字符中间的位置
newText += oldText.substring(lastIndex, oldText.length);
}
return newText;
}
边栏推荐
- What are "full five unique" and "full two unique"? Any difference?
- 一种分布式深度学习编程新范式:Global Tensor
- MySQL:互联网公司常用分库分表方案汇总
- Customer cases | pay attention to the elderly user experience, and the transformation of bank app to adapt to aging should avoid falsehood and be practical
- Practice of online problem feedback module (XV): realize the function of online updating feedback status
- 若依框架代码生成详解
- Submodule cache cache failure
- Details of impala implementation plan
- 177. The nth highest salary (simple)
- Deeply understand the underlying data structure and algorithm of MySQL index
猜你喜欢

Add support for @data add-on in idea

Portraiture5 new and upgraded leather filter plug-in artifact

impala 执行计划详解

C语言const用法详解

【树链剖分】2022杭电多校2 1001 Static Query on Tree

带你了解什么是 Web3.0

安全员及环保员岗位职责

记录一次,php程序访问系统文件访问错误的问题

Win10/win11 lossless expansion of C disk space, cross disk consolidation of C and e disks

FactoryBean的getObject调用时机
随机推荐
Message rejected MQ
索引最佳实践
How many implementation postures of delay queue? Daily essential skills!
Quick sequencing and optimization
【常用搜索问题】111
最大连续子序列(DAY 77)
若依框架代码生成详解
PyCharm中Debug模式进行调试详解
食物链(DAY 79)
Add support for @data add-on in idea
基于.NetCore开发博客项目 StarBlog - (16) 一些新功能 (监控/统计/配置/初始化)
如何进行 360 评估
spark学习笔记(五)——sparkcore核心编程-RDD转换算子
How to uniquely identify a user SQL in Youxuan database cluster
[common search questions] 111
围圈报数(北理工机试题)(DAY 83)
MySQL中文失败问题
docker 创建mysql 8.x容器,支持mac ,arm架构芯片
Spark Learning Notes (V) -- spark core core programming RDD conversion operator
Acwing 2074. Countdown simulation