我有一个CSHTML动态形成的锚标签不调用点击功能
<td id="device-body">
<ul>
<li id="devicesInOffice"></li>
</ul>
</td>
,我试图动态填充锚标记列表的L1标签(如下图所示)
function populateDevicesAvailable(deviceType) {
if (deviceType.id != "") {
$.post(window.getOfficesDevicesUrl, { devicetypeId: deviceType.id },
function (results) {
var items = "";
$.each(results, function (i, device) {
items +=
"<a id='" + device.Id + "' href= '" + "#" + "'
class='devices'
onclick='javascript:populateDeviceInfo()'>" + device.Name + "</a>";
});
$("li#devicesInOffice").append(items);
});
}
else {
$("li#devicesInOffice").html("");
}
};
function populateDeviceInfo() {
}
populateDeviceInfo函数永远不会被调用。当我单击超链接时,我只会得到一个“对象预期”错误。
我也试过其他方式(下面)来调用该函数,但没有任何工作。
$(".devices").click(function() {
populateDeviceInfo();
});
$("li#devicesInOffice a").click(function() {
populateDeviceInfo();
有人可以帮我找到一种方法来调用函数。 谢谢,
Thanks.Got现在工作。 – Lavan
很高兴帮助 - – Rafay