zoukankan      html  css  js  c++  java
  • 动态的创建客户端控件[收藏网络]

    动态的操作客户端控件,现在流行的有2种方法,
    一是innerHTML,这种方法无可厚非,一样可以完成任务,但我不推荐这种方法,
    二是window.document.createElement(),

    例如:在web中有这样一段标记 <div id="TestDIv"></div>

    我们可以这样在DIV中创建一个table:

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

    var row1 = window.document.createElement("tr");

    var cell1 = window.document.createElement("td");

    var cell1_value = window.document.createTextNode("A test table!");

    cell1.appendChild(cell1_value);

    row1.appendChild(cell1);

    table.appendChild(row1);

    window.document.getElementById("TestDiv").appendChild(table);

    同理,创建其他控件的时候,只需要注意要创建的标记就可以了,比如要创建select的时候,他就要append option了

    在修改的时候,要先wnidow.document.getElementById,然后再搜索要更改的节点,

    1. childNodes[x] , 根据序号定位

    2.nextSibling, 当前节点的下个节点

    3.previousSibling 当前节点的上个节点

    4. firstChild

    5. lastChild
    其实用上面的方法也可以操作服务端的一些控件,因为从服务端发送到客服端,在客户端展现的时候,是以最基本的HTML来展现的

  • 相关阅读:
    小波变换的引入,通俗易懂
    Leetcode 437. Path Sum III
    Leetcode 113. Path Sum II
    Leetcode 112 Path Sum
    Leetcode 520 Detect Capital
    Leetcode 443 String Compression
    Leetcode 38 Count and Say
    python中的生成器(generator)总结
    python的random模块及加权随机算法的python实现
    leetcode 24. Swap Nodes in Pairs(链表)
  • 原文地址:https://www.cnblogs.com/hejunrex/p/1652071.html
Copyright © 2011-2022 走看看