随笔分类 - 前端 / JavaScript
摘要:getElementsByTagName 和 getElementsByClassName 这两个方法查找多个 dom 元素,返回的是 htmlcollection 类型,是伪数组而不是真数组,故不能使用数组的方法。 我们可以使用数组原型配合 slice 方法,利用 call,apply,bind
阅读全文
摘要:// 声明变量名为a的对象var a = {a:1,b:2,c:"wangwei"};// 将JSON对象转化为JSON字符,赋值给变量let strResult =JSON.stringify(a)// 查看变量strResult是什么类型typeof strResult // 'string'
阅读全文
摘要:禁止鼠标右键、禁止全选、复制、粘贴; oncontextmenu事件禁用右键菜单;js代码: document.oncontextmenu = function(){ event.returnValue = false; } // 或者直接返回整个事件 document.oncontextmenu
阅读全文
摘要:1、首先查找出元素在数组中的位置即索引(数组中本来就有 indexOf() 方法,方便学习给出代码): Array.prototype.indexOf = function(val) { for (var i = 0; i < this.length; i++) { if (this[i] == v
阅读全文
摘要:[].map.call(document.getElementsByTagName('img'), function (img){ return img.src;}) [].map.call(document.getElementsByTagName('A'), function (img){ re
阅读全文