为了账号安全,请及时绑定邮箱和手机立即绑定
慕课网数字资源数据库体验端
JavaScript进阶篇_学习笔记_慕课网
为了账号安全,请及时绑定邮箱和手机立即绑定

JavaScript进阶篇

慕课官方号 页面重构设计
难度入门
时长 8小时55分
  • 语法: insertBefore(newnode,node); 参数: newnode: 要插入的新节点。 node: 指定此节点前插入节点。var otest = document.getElementById("test");otest.insertBefore(newNode,oldNode);
    查看全部
  • 创建元素节点createElement createElement()方法可创建元素节点。此方法可返回一个 Element 对象。 语法: document.createElement(tagName) 参数: tagName:字符串值,这个字符串用来指明创建元素的类型。 注意:要与appendChild() 或 insertBefore()方法联合使用,将元素显示在页面中。 我们来创建一个按钮,代码如下: <script type="text/javascript"> var body = document.body; var input = document.createElement("input"); input.type = "button"; input.value = "创建一个按钮"; body.appendChild(input); </script> 效果:在HTML文档中,创建一个按钮。 我们也可以使用setAttribute来设置属性,代码如下: <script type="text/javascript"> var body= document.body; var btn = document.createElement("input"); btn.setAttribute("type", "text"); btn.setAttribute("name", "q"); btn.setAttribute("value", "使用setAttribute"); btn.setAttribute("onclick", "javascript:alert('This is a text!');"); body.appendChild(btn); </script> 效果:在HTML文档中,创建一个文本框,使用setAttribute设置属性值。 当点击这个文本框时,会弹出对话框“This is a text!”。
    查看全部
  • var x = content.childNodes; for(i in x){ if(x[i].nodeType == 1){ content.removeChild(x[i]); //document.write(x[i].nodeType); } } 删除子节点
    查看全部
  • 替换元素节点replaceChild() replaceChild 实现子节点(对象)的替换。返回被替换对象的引用。 语法: node.replaceChild (newnode,oldnew ) <oldnode.parentNode.replaceChild(newnode,oldnode);> 参数: newnode : 必需,用于替换 oldnew 的对象。 oldnew : 必需,被 newnode 替换的对象。
    查看全部
  • 删除节点removeChild() removeChild() 方法从子节点列表中删除某个节点。如删除成功,此方法可返回被删除的节点,如失败,则返回 NULL。 语法: nodeObject.removeChild(node) 参数: node :必需,指定需要删除的节点。(nodeObject.childNodes[0]) function clearText() { var content=document.getElementById("content"); // 在此完成该函数 content.removeChild(content.childNodes[0]); while(content.childNodes.length>0){ content.removeChild(content.childNodes[0]); } /*注意:因为每删除一个节点length长度就会发生变化 如果是使用for循环正序删除的话就会错乱,因为你删除第一个后,第二个下表就会变成0第一个,然而倒序删除就解决了这个问题。*/ }
    查看全部
  • 插入节点insertBefore() insertBefore() 方法可在已有的子节点前插入一个新的子节点。 语法:insertBefore(newnode,node); 参数:newnode: 要插入的新节点。 node: 指定此节点前插入节点。 注意: otest.insertBefore(newnode,node); 也可以改为: otest.insertBefore(newnode,otest.childNodes[0]);
    查看全部
  • 插入节点appendChild() 在指定节点的最后一个子节点列表之后添加一个新的子节点。 语法: appendChild(newnode) 参数: newnode:指定追加的节点。
    查看全部
  • document.body.appendChild(pnode);//注意不能直接使用body,应该先用document,之后再引用body
    查看全部
  • var pnode =document.createElement("p"); pnode.className ="message"; pnode.createTextNode("I love JavaScript");//这是错的,应该是document.createElement();才对 body.appendChild(pnode);
    查看全部
  • node.setAttribute("class","delete")和node.className是一样的
    查看全部
  • 数组排序sort() sort()方法使数组中的元素按照一定的顺序排列。 语法: arrayObject.sort(方法函数) 参数说明: 1.如果不指定<方法函数>,则按unicode码顺序排列。 2.如果指定<方法函数>,则按<方法函数>所指定的排序方法排序。 myArray.sort(sortMethod);
    查看全部
    0 采集 收起 来源: 数组排序sort()

    2018-03-22

  • 选定元素slice() slice() 方法可从已有的数组中返回选定的元素。 语法 arrayObject.slice(start,end) 参数说明: 1.返回一个新的数组,包含从 start 到 end (不包括该元素)的 arrayObject 中的元素。 2. 该方法并不会修改数组,而是返回一个子数组。
    查看全部
    0 采集 收起 来源:选定元素slice()

    2015-06-26

  • 颠倒数组元素顺序reverse() reverse() 方法用于颠倒数组中元素的顺序。 语法: arrayObject.reverse() 注意:该方法会改变原来的数组,而不会创建新的数组。 定义数组myarr并赋值,然后颠倒其元素的顺序: <script type="text/javascript"> var myarr = new Array(3) myarr[0] = "1" myarr[1] = "2" myarr[2] = "3" document.write(myarr + "<br />") document.write(myarr.reverse()) </script> 运行结果:
    查看全部
  • 一、nodeName 属性: 节点的名称,是只读的。 1. 元素节点的 nodeName 与标签名相同 2. 属性节点的 nodeName 是属性的名称 3. 文本节点的 nodeName 永远是 #text 4. 文档节点的 nodeName 永远是 #document 二、nodeValue 属性:节点的值 1. 元素节点的 nodeValue 是 undefined 或 null 2. 文本节点的 nodeValue 是文本自身 3. 属性节点的 nodeValue 是属性的值 三、nodeType 属性: 节点的类型,是只读的。以下常用的几种结点类型: 元素类型 节点类型 元素 1 属性 2 文本 3 注释 8 文档 9
    查看全部
    0 采集 收起 来源:节点属性

    2015-06-26

  • 随机数 random() random() 方法可返回介于 0 ~ 1(大于或等于 0 但小于 1 )之间的一个随机数。 语法: Math.random(); 注意:返回一个大于或等于 0 但小于 1 的符号为正的数字值。 我们取得介于 0 到 1 之间的一个随机数,代码如下: <script type="text/javascript"> document.write(Math.random()); </script> 运行结果: 0.190305486195328
    查看全部
    0 采集 收起 来源:随机数 random()

    2018-03-22

举报

0/150
提交
取消
课程须知
你需要具备HTML、css基础知识,建议同学们也可以想学习下js入门篇,快速认识js,熟悉js基本语法,更加快速入手进阶篇!
老师告诉你能学到什么?
通过JavaScript学习,掌握基本语法,制作简单交互式页面
友情提示:

您好,此课程属于迁移课程,您已购买该课程,无需重复购买,感谢您对慕课网的支持!