H5&CSS Basic —— 015. Common DOM Operations (Not translated)
»
001. Free HTTPS Certificate
002. About The Column
003. Visible Area of Browser
004. Why ReactJs
005. Prohibit mobile scaling
006. EM in H5
007. Space width in page
008. H5 Special Characters
009. H5 Restricting Input
010. H5 Font
011. nginx redirection configuration
012. Text Indentation
013. Flex Layout
014. Gradient Borders
015. Common DOM Operations
016. Media Query
017. CSS Selectors
018. CSS alternate lines color
019. fetch
020. JS Attributes Operation
021. scroll div
022. JS for Loop
023. Prohibit Text Selection
024. Precision Controled Float Output
025. Ionic Full Screen
026. SVG Circle
027. SVG Ellipse
028. SVG Arc
029. SVG Elliptical Sector
030. Using WebAssembly
031. JS Checklist checkbox Operation
032. SVG Bezier Curve
033. Threejs Material
034. Luminous Image Styles
035. Web Animation Points
036. CSS Gradient Fonts
037. SVG Rectangle
038. Development Ability for Remuneration
039. Close Browser Default Style for Input
040. Jet Tail Particle Animation
041. Prohibit Desktop Browser Scaling JS
042. Desktop Full Screen Web CSS
043. Display images in self scaling aspect ratio div
044. Bi-side Text Alignment Styles
045. Single line ellipsis
046. Multi-line ellipsis
047. Font Transformation Styles
048. Remove default style of a tag
049. Chinese Characters: Full Width Space
050. DIV lays on DIV
051. Calculating 1rem Pixel Values in JS
052. JS Operations of DOM Parent Nodes and Adjacent Nodes
053. Absolute Coordinates of DOM Elements in JS
054. ToolTips Div
055. Height and Width in JS
056. Nginx configuration for stream media
057. Scroll Bar Style
058. Common Methods for JS Array Operations
059. SVG Fill Style Definition
060. SVG Stroke Style Definition
061. SVG Drawing Lines
062. CSS Background Images Splicing
063. WebSocket
064. JS Calculate DPI
065. GIF Opacity or not
066. Nginx solved CORS problem
067. Look At JsonP before publish
068. Center and Middle Content in Div
069. CSS background image size keeping ratio
070. CSS Frame Animation
071. CSS Same Width Font Display
072. Package
    其实,很多年前就可以用纯JavaScript替代jQuery了。因为,随着所有浏览器的不断升级,原生javascript已基本支持jQuery的所有简便功能。

    也许以后的代码中,会有类似jQ()函数的_qs("#existedDiv")函数来代替document.querySelector("#existedDiv");
    会有类似jQ()函数的_qsAll("div")函数来代替document.querySelectorAll("div");

    在这里总结的是现代Javascript操作DOM的过程。

    DOM的Js操作主要集中在以下几个DOM的属性和方法中:

    1、获取页面上的单DOM节点,.getElementById()或.querySelector():
    var existedDiv=document.getElementById("existedDiv");
    或
    var existedDiv=document.querySelector("#existedDiv");

    2、获取页面上的所有同一类型的DOM节点.querySelectorAll():
    var existedDiv=document.querySelectorAll("div")[0];
    
    3、克隆DOM节点,.cloneNode():
    var newDiv=existedDiv.cloneNode();
    newDiv.id="";
    
    4、在指定DOM元素内添加新的DOM节点,.appendChild():
    document.getElementById("targetDomNode").appendChild(newDiv);

    5、在元素后同级尾部添加新的DOM节点,.parent.appendChild():
    existedDiv.parentNode.appendChild(newDiv);
    
    
    6、在父节内指定插入点,(父节点).insertBefore():
    var newLi = document.createElement( "li" );
    var existedNode= document.querySelector("#existedNode");
    existedNode.insertBefore(newLi,existedNode.children[0]);

    7、调出子节点的方法有两种:childNodes()和children()。childNodes()与children()的区别在于:
    childNodes()包括文本节点和注释节,会把一个div之前之后的空格和\n分别作为一个text节点;
    而,children()只返回元素节点。

    8、输出所有父节点中的DIV的方法为:
    operationBtn.onclick=function(e){
        var element = this;
        var i=0;
        while(element&&element.tagName){
            if(element.tagName.toUpperCase()=='DIV'){
                console.log(i,element);
                i++;
            }
            element=element.parentNode;
        }
    }

    ————www.v-signon.com学习者共勉
                        
«
--Alex.Zhang
--www.v-signon.com Learningers Co-Encouraged
Back
Personal Art: www.up-task.com Unit: Individual
中文 Русский 京ICP备19038994号-2
If the content on this website infringes upon your any rights, please contact me at 1307776259@qq.com for removal