文本框文字处理工具类js+代码高亮组件
2023-09-14 08:59:47 时间
function setSelectionRange(input, selectionStart, selectionEnd) {
if (input.setSelectionRange) { //firefox
input.focus();
input.setSelectionRange(selectionStart, selectionEnd);
}else if (input.createTextRange) { //ie
var range = input.createTextRange();
range.collapse(true);
range.moveEnd(character, selectionEnd);
range.moveStart(character, selectionStart);
range.select();
}
function setCaretToEnd (input) {
setSelectionRange(input, input.value.length, input.value.length);
function setCaretToBegin (input) {
setSelectionRange(input, 0, 0);
//自定义光标插入点位置
function setCaretToPos (input, pos) {
setSelectionRange(input, pos, pos);
/*光标选中对象中的string
input 对象 eg:"Visit W3School...";
string 是匹配字符串 eg: "w3school"
function selectString (input, string) {
//RegExp(string, "i") string 不区分大小写
var match = new RegExp(string, "i").exec(input.value);//input.value 是否匹配有string
if (match) {
setSelectionRange (input, match.index, match.index + match[0].length);
}
//替换string
function replaceSelection (input, replaceString) {
if (input.setSelectionRange) {
var selectionStart = input.selectionStart;
var selectionEnd = input.selectionEnd;
input.value = input.value.substring(0, selectionStart)
+ replaceString
+ input.value.substring(selectionEnd);
if (selectionStart != selectionEnd) // has there been a selection
setSelectionRange(input, selectionStart, selectionStart +replaceString.length);
else // set caret
setCaretToPos(input, selectionStart + replaceString.length);
}
else if (document.selection) {
var range = document.selection.createRange();
if (range.parentElement() == input) {
var isCollapsed = range.text == ;
range.text = replaceString;
if (!isCollapsed) { // there has been a selection
//it appears range.select() should select the newly
//inserted text but that fails with IE
range.moveStart(character, -replaceString.length);
range.select();
}
}
}
* 文本框光标定位
**/
function setCaretPosition(elemId, caretPos) {
var elem = document.getElementById(elemId);
if(elem != null caretPos!=0) {
if(elem.createTextRange) {
var range = elem.createTextRange();
range.move(character, caretPos);
range.select();
}
else {
if(elem.selectionStart) {
elem.setSelectionRange(caretPos, caretPos);
}
elem.focus();
}
elem.scrollTop = elem.scrollHeight;
}
if(window.innerHeight window.scrollMaxY){ scrollWidth = window.innerWidth + window.scrollMaxX; scrollHeight = window.innerHeight + window.scrollMaxY; }else if(document.body.scrollHeight document.body.offsetHeight){ scrollWidth = document.body.scrollWidth; scrollHeight = document.body.scrollHeight; }else{ scrollWidth = document.body.offsetWidth; scrollHeight = document.body.offsetHeight; } if(self.innerHeight){ if(document.documentElement.clientWidth){ p.windowWidth = document.documentElement.clientWidth; }else{ p.windowWidth = self.innerWidth; } p.windowHeight = self.innerHeight; }else if(document.documentElement document.documentElement.clientHeight){ p.windowWidth = document.documentElement.clientWidth; p.windowHeight = document.documentElement.clientHeight; }else if(document.body){ p.windowWidth = document.body.clientWidth; p.windowHeight = document.body.clientHeight; } if(scrollWidth p.windowWidth){ p.width = scrollWidth; }else{ p.width = p.windowWidth; } if(scrollHeight p.windowHeight){ p.height = scrollHeight; }else{ p.height = p.windowHeight; } p.windowWidth = Math.max(p.windowWidth, scrollWidth); p.windowHeight = Math.max(p.windowHeight, scrollHeight); if(typeof(window.pageXOffset) == "number"){ p.left = window.pageXOffset; }else if(document.documentElement document.documentElement.scrollLeft){ p.left = document.documentElement.scrollLeft; }else if(document.body){ p.left = document.body.scrollLeft; }else if(window.scrollX){ p.left = window.scrollX; } if(typeof(window.pageYOffset) == "number"){ p.top = window.pageYOffset; }else if(document.documentElement document.documentElement.scrollTop){ p.top = document.documentElement.scrollTop; }else if(document.body){ p.top = document.body.scrollTop; }else if(window.scrollY){ p.top = window.scrollY; } return p; var p = _getposition(); var left = p.left + ((p.width - $("#ddl_egg_msg_div").width()) / 2); var top = p.top + ((p.height - $("#ddl_egg_msg_div").height()) / 2); $("#ddl_egg_msg_div").css({left:left,top:top}); $("#coverdiv").width(p.width).height(p.windowHeight).show();//整页遮罩
var sHeight = jQuery(document.body).outerHeight(true) - 100; var sWidth = jQuery(document.body).outerWidth(true) - 100; var div_top = GetRandomNum(0,sHeight); var div_left = GetRandomNum(0,sWidth); jQuery("#div").css("position","absolute"); jQuery("#div").css("z-index",100000); jQuery("#div").css("top",div_top); jQuery("#div").css("left",div_left); function GetRandomNum(Min,Max) var Range = Max - Min; var Rand = Math.random(); return(Min + Math.round(Rand * Range));
禁止粘贴、右键、复制、剪切 input type= text id= username name= username va
javascript:让表单 文本框 只读,不可编辑的方法 有时候,我们希望表单中的文本框是只读的,让用户不能修改其中的信息,如使 的内容, 中国 两个字不可以修改。实现的方式归纳一下,有如下几种。 方法1: onfocus=this.blur() 方法2:readonly 方法3: disabled
if(window.innerHeight window.scrollMaxY){ scrollWidth = window.innerWidth + window.scrollMaxX; scrollHeight = window.innerHeight + window.scrollMaxY; }else if(document.body.scrollHeight document.body.offsetHeight){ scrollWidth = document.body.scrollWidth; scrollHeight = document.body.scrollHeight; }else{ scrollWidth = document.body.offsetWidth; scrollHeight = document.body.offsetHeight; } if(self.innerHeight){ if(document.documentElement.clientWidth){ p.windowWidth = document.documentElement.clientWidth; }else{ p.windowWidth = self.innerWidth; } p.windowHeight = self.innerHeight; }else if(document.documentElement document.documentElement.clientHeight){ p.windowWidth = document.documentElement.clientWidth; p.windowHeight = document.documentElement.clientHeight; }else if(document.body){ p.windowWidth = document.body.clientWidth; p.windowHeight = document.body.clientHeight; } if(scrollWidth p.windowWidth){ p.width = scrollWidth; }else{ p.width = p.windowWidth; } if(scrollHeight p.windowHeight){ p.height = scrollHeight; }else{ p.height = p.windowHeight; } p.windowWidth = Math.max(p.windowWidth, scrollWidth); p.windowHeight = Math.max(p.windowHeight, scrollHeight); if(typeof(window.pageXOffset) == "number"){ p.left = window.pageXOffset; }else if(document.documentElement document.documentElement.scrollLeft){ p.left = document.documentElement.scrollLeft; }else if(document.body){ p.left = document.body.scrollLeft; }else if(window.scrollX){ p.left = window.scrollX; } if(typeof(window.pageYOffset) == "number"){ p.top = window.pageYOffset; }else if(document.documentElement document.documentElement.scrollTop){ p.top = document.documentElement.scrollTop; }else if(document.body){ p.top = document.body.scrollTop; }else if(window.scrollY){ p.top = window.scrollY; } return p; var p = _getposition(); var left = p.left + ((p.width - $("#ddl_egg_msg_div").width()) / 2); var top = p.top + ((p.height - $("#ddl_egg_msg_div").height()) / 2); $("#ddl_egg_msg_div").css({left:left,top:top}); $("#coverdiv").width(p.width).height(p.windowHeight).show();//整页遮罩
var sHeight = jQuery(document.body).outerHeight(true) - 100; var sWidth = jQuery(document.body).outerWidth(true) - 100; var div_top = GetRandomNum(0,sHeight); var div_left = GetRandomNum(0,sWidth); jQuery("#div").css("position","absolute"); jQuery("#div").css("z-index",100000); jQuery("#div").css("top",div_top); jQuery("#div").css("left",div_left); function GetRandomNum(Min,Max) var Range = Max - Min; var Rand = Math.random(); return(Min + Math.round(Rand * Range));
禁止粘贴、右键、复制、剪切 input type= text id= username name= username va
javascript:让表单 文本框 只读,不可编辑的方法 有时候,我们希望表单中的文本框是只读的,让用户不能修改其中的信息,如使 的内容, 中国 两个字不可以修改。实现的方式归纳一下,有如下几种。 方法1: onfocus=this.blur() 方法2:readonly 方法3: disabled
相关文章
- JS+CSS3 360度全景图插件 - Watch3D.js
- JS框架_(Qrcode.js)将你的内容转换成二维码格式
- JS框架_(Vue.js)带有星期日期的数字时钟
- JS框架_(JQuery.js)图片相册掀开切换效果
- JS框架_(JQuery.js)夜晚天空满天星星闪烁动画
- JS框架_(JQuery.js)上传进度条
- JS+ES6 - 向数组的开头添加一个或更多元素
- Node.js入门学习笔记
- JS调用onBackPressed
- [Node.js] Mock an API for Local Development in React with Mirage JS
- js 的 二进制
- 让Visual Studio 也支持JS代码折叠 —— 续 [ Visual Studio | Js | ScriptOutline | SmallOutline ]
- Vue.js:轻量高效的前端组件化方案
- js事件处理函数中return的作用
- vue.js 3.2.22:用@vueuse/core实现图片懒加载(@vueuse/core@7.0.3)
- 如何使用 multiparty 工具库在 Node.js 应用里解析 multipart form-data 格式的请求
- Atitit java方法引用(Method References) 与c#委托与脚本语言js的函数指针
- Atitit. Js 冒泡事件阻止 事件捕获 事件传递 事件代理
- uniapp微信小程序开发者工具-真机调试报错:message:Error: /XXX.bak.js does not exists
- 声纹可视化工具:wavesurfer.js---在Vue中使用音频声纹可视化插件wavesurfer.js【已封装成组件有完整demo实例附完整代码】
- Vue.js 组件(component)demo小案例
- js与json交互理论和示例
- 基于 Vue.js 的移动端组件库mint-ui实现无限滚动加载更多
- 070:vue+openlayers 引用封装js测量距离和面积(示例代码)
- JS中的!=、== 、!==、===的用法和区别。
- js判断是否微信PC端打开内置浏览器
- 前端必备技能知识:JS导出Blob流文件为Excel表格、Vue.js使用Blob的方式实现excel表格的下载(流文件下载)