jquery调用javascript方法

本来想找个“优雅”一点的方法,类似C#在调用C++方法时候的Invoke之类的。没找到,后来想想,其实也没必要,直接写就好了,算最优雅了吧。只是少了VS的Intelligence,有点不习惯罢了。

 

事情起因:

想写个带类似treeview功能的table,用的是jquey.load 方法,事件complete的时候想把row append到当前行下面,但失败了,有个语法错误。暂不晓得怎么改。后来网上找到其实Html的table对象本来就有这样的方法,

HTMLTableElement.insertRow();

语法:

var row = HTMLTableElement.insertRow(optional index = -1);

row是一个HTMLTableRowElement对象。

具体例子看看这个吧:

<table id="TableA">
<tr>
<td>Old top row</td>
</tr>
</table>
<script type="text/javascript">

function addRow(tableID) {
  // Get a reference to the table
  var tableRef = document.getElementById(tableID);

  // Insert a row in the table at row index 0
  var newRow   = tableRef.insertRow(0);

  // Insert a cell in the row at index 0
  var newCell  = newRow.insertCell(0);

  // Append a text node to the cell
  var newText  = document.createTextNode('New top row');
  newCell.appendChild(newText);
}

// Call addRow() with the ID of a table
addRow('TableA');

</script>
View Code

 

posted @ 2014-09-03 09:48  Sheldon_Lou  阅读(688)  评论(0编辑  收藏  举报