我有一个表格,其中打开了一个引导模式的链接。我试图传递用户点击链接到模式的行中的一些值,但是我无法从表格单元格获取值。获取表单元值并传递给Javascript
这里的表行的样子:
<tr id="D8F49748-212A-42D8-A188-4C23556027FA">
<td><a href="#" data-contactName="John Citizen" data-contactMobile="0412345678" data-toggle="modal" data-rec-id="1537" data-target="#contactCallModal"><span class="glyphicon glyphicon-earphone"></span> 0412345678</a></td>
</tr>
<tr id="D9AA7744-E138-4A0E-86A2-B8D0CD2007D6">
<td><a href="#" data-contactName="Fred Flinstone" data-contactMobile="0498765432" data-toggle="modal" data-rec-id="1577" data-target="#contactCallModal"><span class="glyphicon glyphicon-earphone"></span> 0498765432</a></td>
</tr>
,这里是我的脚本运行时,在那里我试图模态负载才能到数据contactMobile和数据 - 从所选择的小区CONTACTNAME:
$(window).load(function() {
$('#contactCallModal').on('show.bs.modal', function(e) {
var recID = $(e.relatedTarget).data('rec-id');
var contactMobile = $(e.relatedTarget).data('contactMobile');
var contactName = $(e.relatedTarget).data('contactName');
console.log(recID);
console.log(contactMobile);
console.log(contactName)
});
}); //]]>
当我查看控制台时,我只看到了recID - contactName和contactMobile显示为未定义。不知道我在这里做错了什么?
我觉得这里e.relatedTarget是不是指的那个特定的细胞。你能安慰它并检查吗? – divya