当前位置: 首页 > 编程日记 > 正文

原生js自动完成 [转]

本来想用jquery的autocomplete的,可是需求有些变化,打算改源码,进了源码发现,改起来要的时间太长了,毕竟不是自己写的,改起来慢,在网上开始大肆搜罗资料,终于找到了类似的

本文转自http://www.cnblogs.com/jaiho/archive/2011/02/28/js_autocomplete.html

完成有以下功能:

  • 输入字符会把以输入字符开头的提示出来。
  • 支持上下方向键选择提示选项,支持循环
  • 支持绑定一个数组提示,支持ajax传递输入框值请求数据。
  • 支持多个选择的dom元素一块绑定数据实现输入提示。各dom元素也可以单独绑定自己的数据实现输入提示,互不影响。
  • 支持中文。

首先是js的核心部分,其各部分都有较详细的说明,代码如下:

; (function (window) {/* 插件开始 */var autoComplete = function (o) {var handler = (function () {var handler = function (e, o) { return new handler.prototype.init(e, o); };/* 为每个选择的dom都创建一个相对应的对象,这样选择多个dom时可以很方便地使用 */handler.prototype = {e: null, o: null, timer: null, show: 0, input: null, popup: null,init: function (e, o) {/* 设置初始对象 */this.e = e, this.o = o,this.input = this.e.getElementsByTagName(this.o.input)[0],this.popup = this.e.getElementsByTagName(this.o.popup)[0],this.initEvent();/* 初始化各种事件 */},match: function (quickExpr, value, source) {/* 生成提示 */var li = null;for (var i in source) {if (value.length > 0 && quickExpr.exec(source[i]) != null) {li = document.createElement('li');li.innerHTML = '<a href="javascript:;">' + source[i] + '</a>';this.popup.appendChild(li);}}if (this.popup.getElementsByTagName('a').length)this.popup.style.display = 'block';elsethis.popup.style.display = 'none';},ajax: function (type, url, quickExpr, search) {/* ajax请求远程数据 */var xhr = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();xhr.open(type, url, true);/* 同异步在此修改 */xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");var that = this;xhr.onreadystatechange = function () {if (xhr.readyState == 4) {if (xhr.status == 200) {var data = eval(xhr.responseText);that.match(quickExpr, search, data);/* 相同于成功的回调函数 */} else {alert("请求页面异常!");/* 请求失败 */}}};xhr.send(null);},fetch: function (ajax, search, quickExpr) {search = encodeURI(search);/* 解决ie中文乱码 */var that = this;this.ajax(ajax.type, ajax.url + search, quickExpr, search);},initEvent: function () {/* 各事件的集合 */var that = this;this.input.onfocus = function () {if (this.inputValue) this.value = this.inputValue;var value = this.value, quickExpr = RegExp('^' + value, 'i'), self = this;var els = that.popup.getElementsByTagName('a');if (els.length > 0) that.popup.style.display = 'block';that.timer = setInterval(function () {if (value != self.value) {/* 判断输入内容是否改变,兼容中文 */value = self.value;that.popup.innerHTML = '';if (value != '') {quickExpr = RegExp('^' + value);if (that.o.source) that.match(quickExpr, value, that.o.source);else if (that.o.ajax) that.fetch(that.o.ajax, value, quickExpr);}}}, 200);};this.input.onblur = function () {/*  输入框添加事件 */if (this.value != this.defaultValue) this.inputValue = this.value;clearInterval(that.timer);var current = -1;/* 记住当前有焦点的选项 */var els = that.popup.getElementsByTagName('a');var len = els.length - 1;var aClick = function () {that.input.inputValue = this.firstChild.nodeValue;that.popup.innerHTML = '';that.popup.style.display = 'none';that.input.focus();};var aFocus = function () {for (var i = len; i >= 0; i--) {if (this.parentNode === that.popup.children[i]) {current = i;break;}}//that.input.value = this.firstChild.nodeValue;for (var k in that.o.elemCSS.focus) {this.style[k] = that.o.elemCSS.focus[k];}};var aBlur = function () {for (var k in that.o.elemCSS.blur)this.style[k] = that.o.elemCSS.blur[k];};var aKeydown = function (event) {event = event || window.event;/* 兼容IE */if (current === len && event.keyCode === 9) {/* tab键时popup隐藏 */that.popup.style.display = 'none';} else if (event.keyCode == 40) {/* 处理上下方向键事件方便选择提示的选项 */current++;if (current < -1) current = len;if (current > len) {current = -1;that.input.focus();} else {that.popup.getElementsByTagName('a')[current].focus();}} else if (event.keyCode == 38) {current--;if (current == -1) {that.input.focus();} else if (current < -1) {current = len;that.popup.getElementsByTagName('a')[current].focus();} else {that.popup.getElementsByTagName('a')[current].focus();}}};for (var i = 0; i < els.length; i++) {/* 为每个选项添加事件 */els[i].onclick = aClick;els[i].onfocus = aFocus;els[i].onblur = aBlur;els[i].onkeydown = aKeydown;}};this.input.onkeydown = function (event) {event = event || window.event;/* 兼容IE */var els = that.popup.getElementsByTagName('a');if (event.keyCode == 40) {if (els[0]) els[0].focus();} else if (event.keyCode == 38) {if (els[els.length - 1]) els[els.length - 1].focus();} else if (event.keyCode == 9) {if (event.shiftKey == true) that.popup.style.display = 'none';}};this.e.onmouseover = function () { that.show = 1; };this.e.onmouseout = function () { that.show = 0; };addEvent.call(document, 'click', function () {if (that.show == 0) {that.popup.style.display = 'none';}});/* 处理提示框dom元素不支持onblur的情况 */}};handler.prototype.init.prototype = handler.prototype;/* JQuery style,这样我们在处的时候就不用每个dom元素都用new来创建对象了 */return handler;/* 把内部的处理函数传到外部 */})();if (this.length) {/* 处理选择多个dom元素 */for (var a = this.length - 1; a >= 0; a--) {/* 调用方法为每个选择的dom生成一个处理对象,使它们不互相影响 */handler(this[a], o);}} else {/* 处理选择一个dom元素 */handler(this, o);}return this;};return window.autoComplete = autoComplete;/* 暴露方法给全局对象 *//* 插件结束 */
})(window);

其中了一些全局的自定义函数,如addEvent和在例子中将要用到的getElementsByClassName函数如下:

var getElementsByClassName = function (searchClass, node, tag) {/* 兼容各浏览器的选择class的方法;(写法参考了博客园:http://www.cnblogs.com/rubylouvre/archive/2009/07/24/1529640.html,想了解更多请看这个地址) */node = node || document, tag = tag ? tag.toUpperCase() : "*";if (document.getElementsByClassName) {/* 支持getElementsByClassName的浏览器 */var temp = node.getElementsByClassName(searchClass);if (tag == "*") {return temp;} else {var ret = new Array();for (var i = 0; i < temp.length; i++)if (temp[i].nodeName == tag)ret.push(temp[i]);return ret;}} else {/* 不支持getElementsByClassName的浏览器 */var classes = searchClass.split(" "),elements = (tag === "*" && node.all) ? node.all : node.getElementsByTagName(tag),patterns = [], returnElements = [], current, match;var i = classes.length;while (--i >= 0)patterns.push(new RegExp("(^|\\s)" + classes[i] + "(\\s|$)"));var j = elements.length;while (--j >= 0) {current = elements[j], match = false;for (var k = 0, kl = patterns.length; k < kl; k++) {match = patterns[k].test(current.className);if (!match) break;}if (match) returnElements.push(current);}return returnElements;}
};
var addEvent = (function () {/* 用此函数添加事件防止事件覆盖 */if (document.addEventListener) {return function (type, fn) { this.addEventListener(type, fn, false); };} else if (document.attachEvent) {return function (type, fn) {this.attachEvent('on' + type, function () {return fn.call(this, window.event);/* 兼容IE */});};}
})();

最后是调用的部分,调用和每个参数的部分都有说明和注意事项,再说一个其中source和ajax参数是二选一,如果二者都写只有source是有用的,调用代码如下:

addEvent.call(null,'load',function(){autoComplete.call( getElementsByClassName('autoComplete'), {/* 使用call或apply调用此方法 */source:['0123','023',123,1234,212,214,'033333','0352342',1987,17563,20932],/* 提示时在此数组中搜索 *///ajax:{ type:'post',url:'./php/fetch.php?search=' },/* 如果使用ajax则返回的数据格式要与source相同,如为字符串"[111,222,333,444]"等形式。*/elemCSS:{ focus:{'color':'#00ff00','background':'red'}, blur:{'color':'#ff0000','background':'transparent'} },/* 些对象中的key要js对象中的style属性支持 */input:'input',/* 输入框使用input元素 */popup:'ul'/* 提示框使用ul元素 */});
});

完整的调用示例

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>autoComplete</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> .autoComplete {margin:8px;position:relative;float:left;} .autoComplete input {width:200px;height:25px;margin:0;padding:0;line-height:25px;} .autoComplete ul {z-index:-12;padding:0px;margin:0px;border:1px #333 solid;width:200px;background:white;display:none;position:absolute;left:0;top:28px;*margin-left:9px;*margin-top:2px;margin-top:1px\0;} .autoComplete li {list-style:none;} .autoComplete li a {display:block;color:#000;text-decoration:none;padding:1px 0 1px 5px;_width:97%;} .autoComplete li a:hover {color:#000;background:#ccc;border:none;} </style> <script type="text/javascript"> //<![CDATA[ var getElementsByClassName = function (searchClass, node, tag) {/* 兼容各浏览器的选择class的方法;(写法参考了博客园:http://www.cnblogs.com/rubylouvre/archive/2009/07/24/1529640.html,想了解更多请看这个地址) */ node = node || document, tag = tag ? tag.toUpperCase() : "*"; if(document.getElementsByClassName){/* 支持getElementsByClassName的浏览器 */ var temp = node.getElementsByClassName(searchClass); if(tag=="*"){ return temp; } else { var ret = new Array(); for(var i=0; i<temp.length; i++) if(temp[i].nodeName==tag) ret.push(temp[i]); return ret; } }else{/* 不支持getElementsByClassName的浏览器 */ var classes = searchClass.split(" "), elements = (tag === "*" && node.all)? node.all : node.getElementsByTagName(tag), patterns = [], returnElements = [], current, match; var i = classes.length; while(--i >= 0) patterns.push(new RegExp("(^|\\s)" + classes[i] + "(\\s|$)")); var j = elements.length; while(--j >= 0){ current = elements[j], match = false; for(var k=0, kl=patterns.length; k<kl; k++){ match = patterns[k].test(current.className); if(!match) break; } if(match) returnElements.push(current); } return returnElements; } }; var addEvent=(function(){/* 用此函数添加事件防止事件覆盖 */ if(document.addEventListener){ return function(type, fn){ this.addEventListener(type, fn, false); }; }else if(document.attachEvent){ return function(type,fn){ this.attachEvent('on'+type, function () { return fn.call(this, window.event);/* 兼容IE */ }); }; } })(); ;(function(window){ /* 插件开始 */ var autoComplete=function(o){ var handler=(function(){ var handler=function(e,o){ return new handler.prototype.init(e,o); };/* 为每个选择的dom都创建一个相对应的对象,这样选择多个dom时可以很方便地使用 */ handler.prototype={ e:null, o:null, timer:null, show:0, input:null, popup:null, init:function(e,o){/* 设置初始对象 */ this.e=e, this.o=o, this.input=this.e.getElementsByTagName(this.o.input)[0], this.popup=this.e.getElementsByTagName(this.o.popup)[0], this.initEvent();/* 初始化各种事件 */ }, match:function(quickExpr,value,source){/* 生成提示 */ var li = null; for(var i in source){ if( value.length>0 && quickExpr.exec(source[i])!=null ){ li = document.createElement('li'); li.innerHTML = '<a href="javascript:;">'+source[i]+'</a>'; this.popup.appendChild(li); } } if(this.popup.getElementsByTagName('a').length) this.popup.style.display='block'; else this.popup.style.display='none'; }, ajax:function(type,url,quickExpr,search){/* ajax请求远程数据 */ var xhr = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); xhr.open(type,url,true);/* 同异步在此修改 */ xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); var that=this; xhr.onreadystatechange = function(){ if(xhr.readyState==4) { if(xhr.status==200) { var data = eval(xhr.responseText); that.match(quickExpr,search,data);/* 相同于成功的回调函数 */ }else{ alert("请求页面异常!");/* 请求失败 */ } } }; xhr.send(null); }, fetch:function(ajax,search,quickExpr){ search = encodeURI(search);/* 解决ie中文乱码 */ var that=this; this.ajax(ajax.type,ajax.url+search,quickExpr,search); }, initEvent:function(){/* 各事件的集合 */ var that=this; this.input.onfocus = function(){ if(this.inputValue) this.value = this.inputValue; var value=this.value, quickExpr=RegExp('^'+value,'i'), self=this; var els = that.popup.getElementsByTagName('a'); if(els.length>0) that.popup.style.display = 'block'; that.timer=setInterval(function(){ if(value!=self.value){/* 判断输入内容是否改变,兼容中文 */ value=self.value; that.popup.innerHTML=''; if(value!=''){ quickExpr=RegExp('^'+value); if(that.o.source) that.match(quickExpr,value,that.o.source); else if(that.o.ajax) that.fetch(that.o.ajax,value,quickExpr); } } },200); }; this.input.onblur = function(){/* 输入框添加事件 */ if(this.value!=this.defaultValue) this.inputValue = this.value; clearInterval(that.timer); var current=-1;/* 记住当前有焦点的选项 */ var els = that.popup.getElementsByTagName('a'); var len = els.length-1; var aClick = function(){ that.input.inputValue = this.firstChild.nodeValue; that.popup.innerHTML=''; that.popup.style.display='none'; that.input.focus(); }; var aFocus = function(){ for(var i=len; i>=0; i--){ if(this.parentNode===that.popup.children[i]){ current = i; break; } } //that.input.value = this.firstChild.nodeValue; for(var k in that.o.elemCSS.focus){ this.style[k] = that.o.elemCSS.focus[k]; } }; var aBlur= function(){ for(var k in that.o.elemCSS.blur) this.style[k] = that.o.elemCSS.blur[k]; }; var aKeydown = function(event){ event = event || window.event;/* 兼容IE */ if(current === len && event.keyCode===9){/* tab键时popup隐藏 */ that.popup.style.display = 'none'; }else if(event.keyCode==40){/* 处理上下方向键事件方便选择提示的选项 */ current++; if(current<-1) current=len; if(current>len){ current=-1; that.input.focus(); }else{ that.popup.getElementsByTagName('a')[current].focus(); } }else if(event.keyCode==38){ current--; if(current==-1){ that.input.focus(); }else if(current<-1){ current = len; that.popup.getElementsByTagName('a')[current].focus(); }else{ that.popup.getElementsByTagName('a')[current].focus(); } } }; for(var i=0; i<els.length; i++){/* 为每个选项添加事件 */ els[i].onclick = aClick; els[i].onfocus = aFocus; els[i].onblur = aBlur; els[i].onkeydown = aKeydown; } }; this.input.onkeydown = function(event){ event = event || window.event;/* 兼容IE */ var els = that.popup.getElementsByTagName('a'); if(event.keyCode==40){ if(els[0]) els[0].focus(); }else if(event.keyCode==38){ if(els[els.length-1]) els[els.length-1].focus(); }else if(event.keyCode==9){ if(event.shiftKey==true) that.popup.style.display = 'none'; } }; this.e.onmouseover = function(){ that.show=1; }; this.e.onmouseout = function(){ that.show=0; }; addEvent.call(document,'click',function(){ if(that.show==0){ that.popup.style.display='none'; } });/* 处理提示框dom元素不支持onblur的情况 */ } }; handler.prototype.init.prototype=handler.prototype;/* JQuery style,这样我们在处的时候就不用每个dom元素都用new来创建对象了 */ return handler;/* 把内部的处理函数传到外部 */ })(); if(this.length){/* 处理选择多个dom元素 */ for(var a=this.length-1; a>=0; a--){/* 调用方法为每个选择的dom生成一个处理对象,使它们不互相影响 */ handler(this[a],o); } }else{/* 处理选择一个dom元素 */ handler(this,o); } return this; }; return window.autoComplete = autoComplete;/* 暴露方法给全局对象 */ /* 插件结束 */ })(window); /* 调用 */ addEvent.call(null,'load',function(){ autoComplete.call( getElementsByClassName('autoComplete'), {/* 使用call或apply调用此方法 */ source:['0123','023',123,1234,212,214,'033333','0352342',1987,17563,20932],/* 提示时在此数组中搜索 */ //ajax:{ type:'post',url:'./php/fetch.php?search=' },/* 如果使用ajax则远程返回的数据格式要与source相同 */ elemCSS:{ focus:{'color':'black','background':'#ccc'}, blur:{'color':'black','background':'transparent'} },/* 些对象中的key要js对象中的style属性支持 */ input:'input',/* 输入框使用input元素 */ popup:'ul'/* 提示框使用ul元素 */ }); }); //]]> </script> </head> <body><!-- 这所以使用这么多的z-index是因为ie6和ie7的问题 --> <div> <div class="autoComplete" style="z-index:19"> <input value="input" /> <ul><li></li></ul> </div> <div class="autoComplete" style="z-index:18"> <input value="input" /> <ul><li></li></ul> </div> <div class="autoComplete" style="z-index:17"> <input value="input" /> <ul><li></li></ul> </div> <div class="autoComplete" style="z-index:16"> <input value="input" /> <ul><li></li></ul> </div> <div class="autoComplete" style="z-index:15"> <input value="input" /> <ul><li></li></ul> </div> <div class="autoComplete" style="z-index:14"> <input value="input" /> <ul><li></li></ul> </div> <div class="autoComplete" style="z-index:13"> <input value="input" /> <ul><li></li></ul> </div> <div class="autoComplete" style="z-index:12"> <input value="input" /> <ul><li></li></ul> </div> <div class="autoComplete" style="z-index:11"> <input value="input" /> <ul><li></li></ul> </div> <div class="autoComplete" style="z-index:10"> <input value="input" /> <ul><li></li></ul> </div> <div class="autoComplete" style="z-index:9"> <input value="input" /> <ul><li></li></ul> </div> <div class="autoComplete" style="z-index:8"> <input value="input" /> <ul><li></li></ul> </div> <div class="autoComplete" style="z-index:7"> <input value="input" /> <ul><li></li></ul> </div> <div class="autoComplete" style="z-index:6"> <input value="input" /> <ul><li></li></ul> </div> <div class="autoComplete" style="z-index:5"> <input value="input" /> <ul><li></li></ul> </div> <div class="autoComplete" style="z-index:4"> <input value="input" /> <ul><li></li></ul> </div> <div class="autoComplete" style="z-index:3"> <input value="input" /> <ul><li></li></ul> </div> <div class="autoComplete" style="z-index:2"> <input value="input" /> <ul><li></li></ul> </div> <div class="autoComplete" style="z-index:1"> <input value="input" /> <ul><li></li></ul> </div> <div class="autoComplete" style="z-index:0"> <input value="input" /> <ul><li></li></ul> </div> <div style="clear:both;"></div> </div> <div style="border:3px red double;margin:15px;padding:5px;"> <h3 style="line-height:10px;">Tip:</h3> <ul> <li>输入0、1,2会得到提示。</li> <li>用鼠标或上下键可以选择提示。</li> <li>选择点击鼠标或点回车可以选择选项。</li> <li>可以修改调用处,使各个输入框提示不同内容。</li> </ul> </div> </body> </html>

转载于:https://www.cnblogs.com/meitangdekafei/p/4166857.html

相关文章:

linux 内存管理slab源码,Linux内核源代码情景分析-内存管理之slab-回收

图 1我们看到空闲slab块占用的若干页面&#xff0c;不会自己释放&#xff1b;我们是通过kmem_cache_reap和kmem_cache_shrink来回收的。他们的区别是&#xff1a;1、我们先看kmem_cache_shrink&#xff0c;代码如下&#xff1a;int kmem_cache_shrink(kmem_cache_t *cachep){if…

Vlookup的兄弟lookup讲解

Vlookup是查找函数&#xff0c;lookup也是&#xff0c;但它主要是充当模糊查找。最常见的例子就是算个税等级和成绩区间。我们创建源数据如图结果要求的是300&#xff0c;500&#xff0c;50对应的积分情况。因为数据量大&#xff0c;这里只取小部分。运用lookup函数&#xff0c…

6.python探测Web服务质量方法之pycurl模块

才开始学习的时候有点忽略了这个模块&#xff0c;觉得既然Python3提供了requests库&#xff0c;为什么多此一举学习这个模块。后来才发现pycurl在探测Web服务器的时候的强大。 pycurl是一个用c语言写的libcurl Python实现&#xff0c;支持的操作协议有FTP&#xff0c;HTTP&…

Rocksdb DeleteRange实现原理

文章目录1. 基本介绍2. 两种接口使用及简单性能对比3. DeleteRange 的基本实现3.1 写流程的实现3.2 读流程的实现 -- skyline算法以下涉及到的代码都是基于rocksdb 6.4.0版本进行描述的 1. 基本介绍 DeleteRange接口的设计是为了代替传统的删除一个区间[start,end) 内的key-va…

题目1460:Oil Deposit

题目描述&#xff1a;The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. I…

linux做预警机制,预警通告:Linux内核中TCP SACK机制远程DoS

漏洞描述2019年6月18日&#xff0c;RedHat官网发布报告&#xff1a;安全研究人员在Linux内核处理TCPSACK数据包模块中发现了三个漏洞&#xff0c;CVE编号为CVE-2019-11477、CVE-2019-11478和CVE-2019-11479&#xff0c;其中CVE-2019-11477漏洞能够降低系统运行效率&#xff0c;…

C# 使用xsd文件验证XML 格式是否正确

//创建xmlDocument XmlDocument doc new XmlDocument(); //创建声明段 如<?xml version"1.0" encoding"utf-8" ?> doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", null)); //创建一个根节点 KYTResults Xm…

[蓝桥杯]PREV-23.历届试题_数字游戏

问题描述栋栋正在和同学们玩一个数字游戏。游戏的规则是这样的&#xff1a;栋栋和同学们一共n个人围坐在一圈。栋栋首先说出数字1。接下来&#xff0c;坐在栋栋左手边的同学要说下一个数字2。再下面的一个同学要从上一个同学说的数字往下数两个数说出来&#xff0c;也就是说4。…

Mac 上使用 Clion 阅读C++源码的一些操作

一直在尝试一些写代码方便&#xff0c;阅读代码也很方便的工具&#xff0c;因为使用的是Mac&#xff0c;所以阅读源码上面sourceInsight就没办法用了。 从vscode – sublime – clion 想要可配置性强一点&#xff0c;软件轻一点&#xff0c;也能提供足够的便捷操作&#xff0c…

c语言 字母 八进制表示'/1011',C语言C语言第一课:C语言概述为什么学习C语言怎样学习C语言.DOC...

[摘要]C语言 第一课&#xff1a; C语言概述 为什么学习C语言 怎样学习C语言 参考资料 ----------------------------------------------------------- 入门经典《C语言程序设计》 谭浩强 清华 《汇编语言》 王爽 《The C programming language》 机械工业 《C Primer Plus》 60…

Discuz! X2.5 添加自定义数据调用模块(简单方法)

转&#xff1a;http://521-wf.com/archives/46.html Discuz! X2.5 添加自定义数据调用模块&#xff08;简单方法&#xff09; Discuz!X系列的diy功能还是相当不错的&#xff0c;在对其进行二次开发的过程中&#xff0c;或许需要加入新的数据调用模块&#xff0c;这样可以使你开…

Cassandra数据模型设计最佳实践

2019独角兽企业重金招聘Python工程师标准>>> 本文是Cassandra数据模型设计第一篇&#xff08;全两篇&#xff09;&#xff0c;该系列文章包含了eBay使用Cassandra数据模型设计的一些实践。其中一些最佳实践我们是通过社区学到的&#xff0c;有些对我们来说也是新知识…

矩阵相关概念的物理意义

参考链接&#xff1a; 矩阵乘法的本质是什么&#xff1f; 条件数 病态矩阵与条件数&#xff08;&& 与特征值和SVD的关系&#xff09;矩阵的物理意义&#xff1a;https://blog.csdn.net/NightkidLi_911/article/details/38178533https://blog.csdn.net/NightkidLi_911/a…

Linux 下 进程运行时内部函数耗时的统计 工具:pstack,strace,perf trace,systemtap

简单记录一些 在linux下 统计进程内部函数运行耗时的统计工具&#xff0c;主要是用作性能瓶颈分析。当然以下工具除了pstack功能单一之外&#xff0c;其他的工具都非常强大&#xff0c;这里仅仅整理特定场景的特定用法&#xff0c;用作协同分析。 以下工具需要追踪具体的进程&…

c语言作业扩展名通常为什么,C语言的源程序通常的扩展名是( )

C语言的源程序通常的扩展名是( )更多相关问题【C20】A&#xff0e;asB&#xff0e;afterC&#xff0e;untilD&#xff0e;whenAlthough I spoke to her about the matter several times, she took little ______ of what I s“以质取胜”战略包括三个方面内容&#xff0c;分别是…

VS中C#读取app.config数据库配置字符串的三种方法(转)

关于VS2008或VS2005中数据库配置字符串的三种取法 VS2008建立Form程序时,如果添加数据源会在配置文件 app.config中自动写入连接字符串,这个字符串将会在你利用DataSet,SqlDataAparter,SqlConnection等控件时如影随行地提示你让去选择,或者是新建字符串。如果要用代码的方式取得…

获取线程中抛出的异常信息

1 ScheduledExecutorService service Executors.newScheduledThreadPool(10);2 // 从现在开始delay毫秒之后&#xff0c;每隔一天执行一次&#xff0c;转换为毫秒3 // service.scheduleAtFixedRate(this, delay, period, TimeUnit.MILLISECONDS);4 …

浅谈批处理获取管理员运行权限的几种方法

很多用了Win10版本系统的人都会发现&#xff0c;Windows对程序的运行权限是控制得更加严格了&#xff0c;即使你将UAC控制放至最低&#xff0c;如果没有特别赋予外来程序管理员运行权限的话&#xff0c;很多程序都会运行出错&#xff0c;包括很多用于系统维护的批处理程序由于运…

使用 sched_setaffinity 将线程绑到CPU核上运行

linux 提供CPU调度函数&#xff0c;可以将CPU某一个核和指定的线程绑定到一块运行。 这样能够充分利用CPU&#xff0c;且减少了不同CPU核之间的切换&#xff0c;尤其是在IO密集型压力之下能够提供较为友好的性能。 通过sched_setaffinity 设置 CPU 亲和力的掩码&#xff0c;从…

Objective C内存管理之理解autorelease------面试题

Objective C内存管理之理解autorelease Autorelease实际上只是把对release的调用延迟了&#xff0c;对于每一个Autorelease&#xff0c;系统只是把该Object放入了当前的Autorelease pool中&#xff0c;当该pool被释放时&#xff0c;该pool中的所有Object会被调用Release。 &…

c语言子程序return,c语言return返回到哪

c语言return返回到哪c语言return&#xff0c;返回给了上一级&#xff0c;比如一个递归程序&#xff0c;从第三层返回到第二层&#xff1b;又比如一个普通的子程序&#xff0c;那就返回到主程序中去。主程序中return返回给了操作系统。比如下面一个c程序int sum(int a, int b) {…

有关 schema

2019独角兽企业重金招聘Python工程师标准>>> 主要分析2点 &#xff1a;schema含义 以及 多schema下的XA处理 A schema is a collection of database objects (used by a user.). Schema objects are the logical structures that directly refer to the database’…

关于查询ios的app更新的历史版本记录

https://www.qimai.cn 推荐七麦数据 可以查询app的各种版本更新内容 由于历史久远忘记了自己app第一次上架的时间 通过这个可以查询 转载于:https://www.cnblogs.com/ccw-congcong/p/10593917.html

关于 Rocksdb 性能分析 需要知道的一些“小技巧“ -- perf_context的“内功” ,systemtap、perf、 ftrace的颜值

文章目录内部工具包含头文件接口使用核心指标Perf ContextIOStats Context外部工具Systemtap 工具Perf工具Ftrace 工具2020.8.20 23:23 &#xff0c;又到了夜深人静学习时&#xff0c;不断得思考总结总会让繁忙一天的大脑得到舒缓。作为单机存储引擎&#xff0c;Rocksdb总会被嵌…

一维数组求平均值c语言编程软件,c语言编程:用数组名作函数参数,编写一个对一维数组求平均值的函数,并在主函数中调用它...

#includeincludeint main(){void sort1(char*p1);void print(char*p2);static char*name[]{"zhangwww.book1234.com防采集请勿采集本网。#include #include #include float b(float arr[],int n); //<<<不知道你说的第2&#xff0c;4&#xff0c;5语句对应的是什…

2014年10月18日

我姐一个一点追求都没有弄的我气死了.女人管不住自己的臭嘴就让人烦死/ 还能不能嫁出去 蠢 女人说一个男的没追求没出息就是找枪口撞 蠢死转载于:https://www.cnblogs.com/wangduqiang/p/4180892.html

接口响应慢?那是你没用 CompletableFuture 来优化!

大多数程序员在平时工作中,都是增删改查。这里我跟大家讲解如何利用CompletableFuture优化项目代码,使项目性能更佳!

SQL Server 2012入门T-SQL基础篇:(8)Delete语句

基本的语法格式如下:Deleteform表名[where条件语句]此语句将删除表的部分或者全部记录;(1)带WHERE条件子句,将删除符合条件的记录:可以看到已经删除了"EmployeeKey1"的记录;(2)不带条件的delete的语句,将表中删除所有记录;转载于:https://blog.51cto.com/281816327/1…

30张图带你彻底理解红黑树

当在10亿数据进行不到30次比较就能查找到目标时,不禁感叹编程之魅力!人类之伟大呀!—— 学红黑树有感。终于,在学习了几天的红黑树相关的知识后,我想把我所学所想和所感分享给大家。红黑树是一种比较难的数据结构,要完全搞懂非常耗时耗力,红黑树怎么自平衡?什么时候需要左旋或右旋?插入和删除破坏了树的平衡后怎么处理?等等一连串的问题在学习前困扰着我。如果你在学习过程中也会存在我的疑问,那么本文对你会有帮助,本文帮助你全面、彻底地理解红黑树!

Linux内核分析--理解进程调度时机、跟踪分析进程调度和进程切换的过程

学号后三位:426 原创作品转载请注明出处 https://github.com/mengning/linuxkernel/ 1.进程的创建 除了0号进程&#xff08;系统创建的&#xff09;之外&#xff0c;linux系统中都是由其他进程创建的。创建新进程的进程&#xff0c;即调用fork函数的进程为父进程&#xff0c;…