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=跳转页面;

  • 相关阅读:
    HubbleDotNet 开源全文搜索数据库项目指定单词权重
    AcWing 12. 背包问题求具体方案
    Acwing 1058 股票买卖V
    AcWing 487 金明的预算方案
    AcWing 426. 开心的金明
    AcWing 1052. 设计密码
    AcWing 11. 背包问题求方案数
    AcWing 10. 有依赖的背包问题
    AcWing 1057. 股票买卖 IV
    AcWing 734 能量石
  • 原文地址:https://www.cnblogs.com/marswenze/p/12837203.html
Copyright © 2011-2022 走看看