首页 > 编程语言 > 详细

jquery调用javascript方法

时间:2014-09-03 10:50:06      阅读:477      评论:0      收藏:0      [点我收藏+]

本来想找个“优雅”一点的方法,类似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对象。

具体例子看看这个吧:

bubuko.com,布布扣
<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

 

jquery调用javascript方法

原文:http://www.cnblogs.com/sheldon-lou/p/3952977.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!