Javascript HTML5数据-*属性未按预期工作
我有一个带有HTML5 doctype的页面,我试图在我的表的Javascript HTML5数据-*属性未按预期工作,javascript,php,html,Javascript,Php,Html,我有一个带有HTML5 doctype的页面,我试图在我的表的元素中使用data属性,如下所示: while($res = mysql_fetch_assoc($U)){ if($c == "table-row-dark"){ $c = "table-row-light"; }else{ $c = "table-row-dark"; } echo "<tr data-id='".$res['rid']."' class='".
元素中使用data属性,如下所示:
while($res = mysql_fetch_assoc($U)){
if($c == "table-row-dark"){
$c = "table-row-light";
}else{
$c = "table-row-dark";
}
echo "<tr data-id='".$res['rid']."' class='".$c."'>"
."<td>".$res['fname']." ".$res['lname']."</td>"
."<td>".$res['company']."</td>"
."<td>".$res['rcity'].", ".$res['rstate']."</td>"
."<td>".$res['rphone']."</td>"
."</tr>";
}
问题是,当发出
url
警报时,它将属性值显示为null
。我做错了什么?如何在保持跨浏览器兼容性的同时修复它?尝试更改row.getAttribute('data-id')
tothis.getAttribute('data-id')代码>您将通过标记名获取元素,然后尝试使用jquery函数对其进行查询
this.getAttribute('data-id');
方法是这样的。当您检查HTML时,您在数据id属性中看到了什么?另外,如果您要麻烦对PHP字符串使用双引号,对HTML使用单引号,至少要使用变量插值<代码>回声“”
等等@Jessica
也许可以尝试使用javascript连接(.concat()
)而不是+作为字符串?我忘了在JS中是否允许在字符串上使用+了?使用插值与我现在所做的相反有什么好处?PHP可以正常工作。
this.getAttribute('data-id');