zoukankan      html  css  js  c++  java
  • DOM对象-2

    添加删除元素

    添加元素

    var p = document.createElement(element);创建yige元素标签

    document.createTextNode(文本);标签的内容

    document.appendChild(element);添加

    例子;var p = document.createElement(‘p’);

    var nod = document.createTextNode(‘新段落’);

    p.appendChild(nod);

    删除元素

    document.getElementById(‘id’).appendChild(p);

    document.removeChild(element);

    例子:var parent = document.getElementById(‘div1’);(父级)

          var child = document.getElementById(‘p1’);(子级)

    parent.removeChild(child);

     替换元素

    document.replaceChild(newnode,oldnode);

    例子:var para = document.createElement("p");

    var node = document.createTextNode("这是新文本。");

    para.appendChild(node);

    var parent = document.getElementById("div1");

    var child = document.getElementById("p1");

    parent.replaceChild(para, child);

    写入HTML流;千万不要在文档加载后使用 document.write()。这么做会覆盖文档

    document.write(text);

    定时器

    事件属性:alert(message);警告框;

    var i=setInterval(function(){},1000)定时器;每隔多少秒运行一次

    clearInterval( i)取消定时器;

    var i= setTimeout(function(){},1000);单词定时器,及页面加载完成后多长时间过后运行;只运行一次

    clearTimeout(i);取消定时;

    scrollTo(xpos,ypos);滑轮的x值跟y值

    window.onload=function(){};加载完执行,

    window.history.back();后退;

    window.location.href=跳转页面;

  • 相关阅读:
    python 找到列表中满足条件的元素
    android activity动画anim
    Maven实战(Maven+Nexus建立私服【Linux系统】)
    linux命令
    服务端工程师入门与进阶 Java 版
    jvm字节占用空间分析
    Spark Streaming容错的改进和零数据丢失
    Spark分布式计算和RDD模型研究
    Apache Curator入门实战
    spark简单总结—短小精悍
  • 原文地址:https://www.cnblogs.com/marswenze/p/12837203.html
Copyright © 2011-2022 走看看