当前位置:网站首页>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;
}
边栏推荐
- Database usage security policy
- be based on. NETCORE development blog project starblog - (16) some new functions (monitoring / statistics / configuration / initialization)
- 队列达到最大长度代码实战
- AcWing 2074. 倒计数 模拟
- OC-消息机制
- 基于.NetCore开发博客项目 StarBlog - (16) 一些新功能 (监控/统计/配置/初始化)
- 阶乘末尾0的数量
- Best practices of opentelemetry in service grid architecture
- Sqlserver select * can you exclude a field
- 客户端发送一条sql如何与服务器交互
猜你喜欢

数据库概论 - 数据库的介绍

带你了解什么是 Web3.0

Comprehensive care analysis lyriq Ruige battery safety design

Fastboot刷机

Pytorch损失函数总结

Activiti5.22.0扩展支持达国产数据库,以GBase据库为例

注解@Autowired和@Resource的区别总结

196. Delete duplicate email addresses

Spark Learning Notes (V) -- spark core core programming RDD conversion operator

Worthington果胶酶的特性及测定方案
随机推荐
What are "full five unique" and "full two unique"? Any difference?
【正则】判断, 手机号,身份证号
Submodule cache cache failure
Explain
[understanding of opportunity -52]: the depth of communication varies from person to person
Detailed explanation of const usage in C language
【树链剖分】2022杭电多校2 1001 Static Query on Tree
Activiti5.22.0 extension supports domestic databases, taking gbase database as an example
Database usage security policy
技术风向标 | 云原生技术架构成熟度模型解读
国内服务器与海外服务器用1个数据库,怎样可以访问的快?
Best practices of opentelemetry in service grid architecture
安全员及环保员岗位职责
Spark Learning Notes (VI) -- spark core core programming RDD action operator
Byte side: can TCP and UDP use the same port?
Acwing 2074. Countdown simulation
如何进行 360 评估
spark:计算不同分区中相同key的平均值(入门级-简单实现)
Worthington木瓜蛋白酶解离系统解决方案
Abbkine AbFluor 488 细胞凋亡检测试剂盒特点及实验建议