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

  • 相关阅读:
    *VC编程规范
    C++的va_start() va_end()函数应用(转)
    * C++类的分解,抽象类与纯虚函数的需要性
    *C++中的回调
    *C++中使用接口
    C++模版使用
    *获取mac地址的方法
    *数字——字符之间的转换(转)
    eclipse雕虫小技一:eclipse打开文件目录
    Hibernate升级后注解方式的对象关系映射
  • 原文地址:https://www.cnblogs.com/marswenze/p/12837203.html
Copyright © 2011-2022 走看看