dom

react-虚拟dom

南楼画角 提交于 2020-01-16 13:20:00
React中几个核心的概念 虚拟DOM(Virtual Document Object Model) DOM的本质是什么:就是用JS表示的UI元素 DOM和虚拟DOM的区别: DOM是由浏览器中的JS提供功能,所以我们只能人为的使用 浏览器提供的固定的API来操作DOM对象; 虚拟DOM:并不是由浏览器提供的,而是我们程序员手动模拟实现的,类似于浏览器中的DOM,但是有着本质的区别; 为什么要实现虚拟DOM: 什么是React中的虚拟DOM: 虚拟DOM的目的: Diff算法 tree diff:新旧DOM树,逐层对比的方式,就叫做 tree diff,每当我们从前到后,把所有层的节点对比完后,必然能够找到那些 需要被更新的元素; component diff:在对比每一层的时候,组件之间的对比,叫做 component diff;当对比组件的时候,如果两个组件的类型相同,则暂时认为这个组件不需要被更新,如果组件的类型不同,则立即将旧组件移除,新建一个组件,替换到被移除的位置; element diff:在组件中,每个元素之间也要进行对比,那么,元素级别的对比,叫做 element diff; key:key这个属性,可以把 页面上的 DOM节点 和 虚拟DOM中的对象,做一层关联关系; <!DOCTYPE html> <html lang="en"> <head> <meta

Problems with multiple attributes while using PHP Simple HTML DOM

a 夏天 提交于 2020-01-16 13:19:21
问题 I use this code for getting elements of left navigation bar: function parseInit($url) { $ch = curl_init(); $timeout = 0; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $data = curl_exec($ch); curl_close($ch); return $data; } $data = parseInit("https://www.smile-dental.de

javascript modify style of an element

北城余情 提交于 2020-01-16 13:04:32
问题 As a newbie to javascript I am trying to code a function that adds yellow divs to page (like post-its) wherever the user clicks. Event handling seems fine, but somehow the style properties I want are not applied. Here is my script : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <script type="text/javascript"> function get_position(e){ //ie if(document.all){ curX = event.clientX; curY = event.clientY; } /

Get DOM tree with javascript

早过忘川 提交于 2020-01-16 06:07:05
问题 Good afternoon, I am developing a small script that analyzes the DOM of an HTML page and write on screen the tree of nodes . It is a simple function that is called recursively for get all nodes and their children. The information for each node is stored in an array ( custom object ). I have gotten get all the nodes in the DOM, but not how to paint in a tree through nested lists. JSFIDLE https://jsfiddle.net/06krpdyh/ HTML <html> <head> <title>Formulario para validar</title> <script type="text

How to add a var to href

邮差的信 提交于 2020-01-16 05:17:05
问题 I need something like this: var link = " http://www.google.com"; <a href='link' /> So I need to use a variable as href attribue of a link. Is this possible? It worked with "<a href= '" + link + "' />" . Is there a better way? 回答1: You should set the href value on the server, it is bad design to use scripting for this. However, to answer the question, it can be done by using script to set the href property of the A element once it is in the DOM, e.g.: <a href="<a useful URI if javascript not

How to temporary suspend browser rendering then resume for the whole page

白昼怎懂夜的黑 提交于 2020-01-16 04:22:25
问题 I know this could be sounding weird at first read. Please do not drop the idea as a nonsense just because of this. Suspend and resume rendering is a common thing since complex GUIs arose, in many UI frameworks including Java GUIs and .NET has similar facility. The main idea behind this a) [do not use resources unnecessary] and b) [do not flicker the screen] while a multi step screen/control update in progress and being in temp stages. My concern is mainly about the navigation. When the user

Get multiple corresponding values from different HTML tags to use in a function

一世执手 提交于 2020-01-16 03:27:05
问题 I am trying to call a funtion by pressing the button on my sidebar. The function should find checked checkboxes of <input> tags and get corresponding names from <a> tags . Then it passes names to backend Google Apps script function (which works) to get an array of calendars from sheet. Then it collects an array of names and calendars into one object{} and passes it to another backend function which gets calendar events and writes them to a sheet (which also works). The final result should be:

js 获取当前元素距离窗口的距离

筅森魡賤 提交于 2020-01-16 03:15:51
获取dom到body左侧和顶部的距离-getBoundingClientRect 平时在写js的时候,偶尔会需要用js来获取当前div到 body 左侧、顶部的距离。网上查一查,有很多都是通过offsetTop、offsetLeft来计算出来的。我按照网上的查到的资料用了一次,算出来了一堆错误答案。下面我要分享的这个方法,兼容性很好(ie4都ok),而且很方便,不会算错。 这个方法就是 getBoundingClientRect。 1.getBoundingClientRect方法简介 getBoundingClientRect 返回的是一个 DOMRect 对象,是一组矩形集合,我们这次所使用的返回值主要是left、top、bottom和right。其余的返回值width、height、x、y这次用不到,就不再讨论。 使用方法如下: let domToTop = dom.getBoundingClientRect().top // dom 的顶边到视口顶部的距离 let domToLeft = dom.getBoundingClientRect().left // dom 的左边到视口左边的距离 let domToBottom = dom.getBoundingClientRect().bottom // dom 的底边到视口顶部的距离 let domToRight = dom

【HTML】Dom操作

风流意气都作罢 提交于 2020-01-16 02:21:36
tips: 1.createTextNode()和innerHTML区别:前者不消化html标签,就纯文本;后者消化 js的括号问题 1. <div οnclick='myfun () '>c点我!</div> nodeName、nodeValue、nodeType 节点: <div id='div1' name='myname'>text</div> var id_name=document.getElementById('div1')// 元素节点 var name=id_name.getAttribute('name'); // 属性节点 alert(id_name);//div1 alert(‘元素节点: ’+ id_name.nodeName+', '+ id_name. namenodeType+', '+ id_name.nodeValue);// 元素节点: div, ELEMENT_NODE, null alert(‘属性节点: ’+ name.nodeName+', '+name.nodeType+', '+name.nodeValue);// 属性节点: name, ATTRIBUTE_NODE, myname .innerHTML='' 更改css样式: div1.style.background='red'; 创建新的元素(createElement()

vue的常用组件方法应用

一个人想着一个人 提交于 2020-01-16 01:07:55
项目技术: webpack + vue + element(mint-ui, etc...) + axois (vue-resource) + less-loader+ ... vue的操作的方法案例: 1.数组数据还未获取到,做出预加载的动画 <el-carousel :interval="3000" type="card" height="200px" class="common-mt-md"> <el-carousel-item v-for="item in movieArr" :key="item.id" class="text-center"> <img v-bind:src="item.images.small" alt="电影封面" class="ticket-index-movie-img"> </el-carousel-item>// 实际显示的内容-跑马灯 <div v-if="!movieArr.length" class="ticket-index-movie-loading"> <span class="el-icon-loading "></span> </div>// 当 movirArr的数组为空的时候,做出的预加载 loading </el-carousel> 2. 按钮状态的判断,按钮能不能点的问题 <p v-if="