js
共 3 篇文章
从js数组中判断存在字符串和删除指定字符串
判断存在: function contains(arr, str) { var i = arr.length; // 从数组中判断str是否存在 while (i--) { if (arr[i] === str) { return true; } } return false; } 删除指定项: function remove(arr, str) { var arrA = arr.split(","); var arrNew = new Array(); //从数组中删除指定str for(var i = 0; i < arrA.length; i++){ if(str != arrA[i]…
2014-12-03 10:24 · js · JavaScript
js的prototype原型设计模式
1.js对象的继承方式使用prototype原型模式。 2.js的方法可以分为以下三类: a.类方法 b.对象方法 c.原型方法 function People(name) { this.name=name; //对象方法 this.Introduce=function(){ alert("My name is "+this.name); } } //类方法 People.Run=function(){ alert("I can run"); } //原型方法 People.prototype.IntroduceChinese=function(){ alert("我的名字是"+this.n…
2014-09-16 15:06 · js · prototype
阻止js bubble事件
当父div与子div同时具有不同click事件时,为了防止dom冒泡,防止点击子div时触发两个事件,则需要在子div的click事件中阻止bubble事件的发生。 代码如下。 function cancelBubble(e){ if (e && e.stopPropagation) { // 非IE的情况 e.stopPropagation() } else { // IE的情况 window.event.cancelBubble=true } }
2014-09-11 20:24 · js · JS