Dom操作技术《javascript高级程序设计》阅读笔记

本文详细介绍了动态脚本加载、样式应用及表格创建的基础知识,适合前端开发者快速掌握。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

菜鸟记录书中的基础知识,以便日后复习:

1,动态脚本:

  function loadScriptString(code){

    var script=document.createElement("script");

    script.type="text/javascript";

    try{

      script.appendChild(document.cteateTextNode(code));//ie中会发生异常

      }catch(ex){

      script.text=code;

      }

}

2,动态样式:

    function loadStyleString(css){

    var style=document.createElement("style");

    style.type="text/css";

    try{

      style.appendChild(document.cteateTextNode(css));//ie中会发生异常

      }catch(ex){

      style.styleSheet.cssText=css;

      }

    var head=document.getElementByTagName("head")[0];

    head.appendChild(style);

}

3,操作表格:

  假如要创建下面的HTML表格:

  <table border="1" width="100%">

    <tbody>

      <tr>

        <td>Cell 1,1</td>

        <td>Cell 2,1</td>

      </tr>

      <tr>

        <td>Cell 1,2</td>

        <td>Cell 2,2</td>

      </tr>

    </tbody>

  </table>

  var table=document.createElement("table");

  table.border=1;

  table.width=100%;

  var tbody=document.createElement("tbody");

  table.appendChild(tbody);

  //创建第一行

  tbody.insertRow(0);

  tbody.row[0].insertCell(0);

  tbody.row[0].cells[0].appendChild(document.createTextNode("Cell 1,1");

    tbody.row[0].insertCell(1);

  tbody.row[0].cells[1].appendChild(document.createTextNode("Cell 2,1");

  //创建第二行

  tbody.insertRow(1);

  tbody.row[1].insertCell(0);

  tbody.row[1].cells[0].appendChild(document.createTextNode("Cell 1,2");

    tbody.row[1].insertCell(1);

  tbody.row[1].cells[1].appendChild(document.createTextNode("Cell 2,2");

  document.body.appendChild(table);

转载于:https://www.cnblogs.com/rason2008/archive/2011/10/07/2200742.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值