JQuery添加到表格单元格的链接 [英] JQuery Adding link to a table cell
本文介绍了JQuery添加到表格单元格的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将一个标签添加到表格单元格中。我的代码一直工作到这里显示的最后一行,此时我得到一个例外
I'm trying to add an a tag to a table cell. My code is working all the way up to the final line shown here, at which point I get an exception of
'TypeError:Object不支持这个属性或方法'
'TypeError: Object doesn't support this property or method'
从我读过的内容来看,appendChild应该是我桌上单元格的一种方法。
From what I've read, appendChild should be a method on my table cell.
var rowId = "#rowid-" + response.id;
var actionCell = $('#itemlist').find(rowId).find(actionCellId);
//Add my Edit link
link = document.createElement('a');
link.setAttribute('href', '/MYSite/Item/Edit?itemID=' + response.id);
link.setAttribute('id', 'edit-' + response.id);
var linkText = document.createTextNode('Edit');
link.appendChild(linkText);
//Exception occurs on this line
actionCell.appendChild(link);
推荐答案
替换为:
link = document.createElement('a');
link.setAttribute('href', '/MYSite/Item/Edit?itemID=' + response.id);
link.setAttribute('id', 'edit-' + response.id);
var linkText = document.createTextNode('Edit');
link.appendChild(linkText);
//Exception occurs on this line
actionCell.appendChild(link);
这个:
$('<a>Edit</a>').attr({
'href': '/MYSite/Item/Edit?itemID=' + response.id,
'id': 'edit-' + response.id
}).appendTo(actionCell);
这篇关于JQuery添加到表格单元格的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文