zl程序教程

您现在的位置是:首页 >  后端

当前栏目

文本框文字处理工具类js+代码高亮组件

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