zoukankan      html  css  js  c++  java
  • js 小总结

                                数组操作

    创建数组:var standTerm = new Array("维护","维修");

                var arr = new Array(); 

    数组长度:length属性

    数组中添加:push()

    清空数组:arrName.length=0

                                 字符串操作

    去字符串最后一个字符: strName.substring(0,strName.length-1)

                                 表格操作

    获取表格长度:document.getElementById("tableID").rows.length;

    插入行和列:   newRow = document.getElementById("tableID").insertRow(位置);

                       for(i=0;i<列数;i++){

                           var newColumn = newRow.insertCell(i)

                           //根据i的不同往里面添加不同的数据,自己填写

                           ...

                       }

    删除表格行:document.getElementById("tableID").deteleRow(行索引)

    获取行索引:行对象.rowIndex

    获取父对象:对象.parentElement

                              元素对象操作

    创建元素:createElement(元素名称)

      举例:

      var element = document.createElement('input)

      element.type='text'

      element.id=''

      element.value=''

      创建元素之后可以放在单元格里面。

      newColumn.appendChild(element);

      如果不创建元素,用如下方法也可以往单元格里面插入内容

      newColumn.innerHTML="<input id='' value='' type='' />"

    获取对象:document.getElementById();

    向元素中添加内容:对象.innerHTML("<input type='text' name='myName' />");会覆盖吗?

                  修改元素样式

    对象.style.样式名称="样式值"; 例:对象.style.display="none";

  • 相关阅读:
    PAT (Advanced Level) 1060. Are They Equal (25)
    PAT (Advanced Level) 1059. Prime Factors (25)
    PAT (Advanced Level) 1058. A+B in Hogwarts (20)
    PAT (Advanced Level) 1057. Stack (30)
    PAT (Advanced Level) 1056. Mice and Rice (25)
    PAT (Advanced Level) 1055. The World's Richest (25)
    PAT (Advanced Level) 1054. The Dominant Color (20)
    PAT (Advanced Level) 1053. Path of Equal Weight (30)
    PAT (Advanced Level) 1052. Linked List Sorting (25)
    PAT (Advanced Level) 1051. Pop Sequence (25)
  • 原文地址:https://www.cnblogs.com/mrxiaohe/p/5221158.html
Copyright © 2011-2022 走看看