queryselector

JS获取DOM元素的方法(8种)

ぃ、小莉子 提交于 2019-11-27 05:05:10
原文地址:https://www.cnblogs.com/web-record/p/10131782.html JS获取DOM元素的方法(8种) 通过ID获取(getElementById) 通过name属性(getElementsByName) 通过标签名(getElementsByTagName) 通过类名(getElementsByClassName) 通过选择器获取一个元素(querySelector) 通过选择器获取一组元素(querySelectorAll) 获取html的方法(document.documentElement) document.documentElement是专门获取html这个标签的 获取body的方法(document.body) document.body是专门获取body这个标签的。 1.通过ID获取(getElementById) document.getElementById('id') 上下文必须是document。 必须传参数,参数是string类型,是获取元素的id。 返回值只获取到一个元素,没有找到返回null。 2.通过name属性(getElementsByName) document.getElementsByName('name') 上下文必须是document。内容 必须传参数,参数是是获取元素的name属性。

dom元素和class常用操作

送分小仙女□ 提交于 2019-11-26 16:06:58
创建 document.createElement() document.createTextNode() 克隆 document.cloneNode() 删除 removeChild() 替换 replaceChild(newnode,oldnode) 插入 appendChild() insertBefore() 把节点插入到父节点的某个兄弟节点的前面。所以他有两个参数,insertBefore(newItem,existingItem) var newItem=document.createElement("LI") var textnode=document.createTextNode("Water") newItem.appendChild(textnode) var list=document.getElementById("myList") list.insertBefore(newItem,list.childNodes[1]); 插入前 Coffee Tea 插入后 Water Coffee Tea 查找 document.getElementsByTagName() //通过标签名称 document.getElementsByClassName() //通过标签名称 document.getElementsByName() //通过元素的Name属性的值

Scraper throws errors instead of quitting the browser when everything is done

独自空忆成欢 提交于 2019-11-26 14:45:48
问题 I've written a scraper to parse movie information from a torrent site. I used IE and queryselector . My code does parse everything. It throws errors instead of quitting the browser when everything is done. If I cancel the error box then I can see the results. Here is the full code: Sub Torrent_Data() Dim IE As New InternetExplorer, html As HTMLDocument Dim post As Object With IE .Visible = False .navigate "https://yts.am/browse-movies" Do While .readyState <> READYSTATE_COMPLETE: Loop Set

js和jq

时光毁灭记忆、已成空白 提交于 2019-11-26 03:38:49
复习 """1、js变量:不写 | var | let | const2、js的基本数据类型:值类型:number | string | boolean | undefined 引用类型:object | function 其它: null | Array | Date3、随机数:parseInt(Math.random() * (n - m + 1)) + m4、类型转换:"" + number => string | +string => number | parseInt(string) => number5、运算符:/ | ++ | === | &&、||、! | 条件? 结果1:结果26、类型的运用:string | [1, 2, 3] splice(index, count, args) | {}7、流程控制8、函数function 函数名(){}var 函数名 = function (){}let 函数名 = () => {}""" 今日内容 """1、js操作页面文档 选择器 页面内容 页面样式 页面事件 2、jq操作页面文档 http://jquery.cuishifeng.cn/""" js操作页面三步骤 <!DOCTYPE html><html><head> <meta charset="utf-8"> <title>操作页面的三步骤</title><

虚拟dom节点,支持querySelector

老子叫甜甜 提交于 2019-11-25 22:21:27
虚拟dom节点,支持querySelector, 方法: hasQuerySelector 输入css选择器,判断是否选中dom querySelectorToHtml 输入css选择器,输出命中的html querySelector 输入css选择器,输出bitmap数据 HtmlNode.js //HtmlNode.js const Api=require('./Api'); const compiler = require('vue-template-compiler'); //命中规则 /*css rule矩阵, 行对应selector '.id', 列对应html节点 ['body','body div','body div div','body div p','body div span','body div span a'] [ [0,0,0,0,1,0], ] */ class HtmlNode{ constructor(htmlText){ let htmlAst=htmlText==='string'?compiler.compile(htmlText).ast:htmlText; //记录selector查找历史 this.selectotCache={}; //构建html语法树和矩阵bitmap this.htmlAst=htmlAst; this