我将数据分配到 $clicked_row:
$clicked_row.data("row", data);
以下代码不起作用:
alert($clicked_row.hasData("row")); // want to have Boolean output
但是,这有效:
alert($clicked_row.data("row")); // output the data
为什么?
我将数据分配到 $clicked_row:
$clicked_row.data("row", data);
以下代码不起作用:
alert($clicked_row.hasData("row")); // want to have Boolean output
但是,这有效:
alert($clicked_row.data("row")); // output the data
为什么?
你应该试试这个:
$.hasData($clicked_row);
此解决方案的来源:hasData 上的文档
For a short discussion on why hasData isn't a property of data objects, I refer you to this thread. In summary, you should stick to using .attr
to determining if the element has a given attribute set, rather than just wanting to know if it has any attribute set. It will return undefined
if the attribute isn't set.
失踪"
alert($clicked_row.hasData("行在这里));
或者你只是错误地分配数据。来自 jQuery 文档:
jQuery.data(document.body, 'foo', 52);
jQuery.data(document.body, 'bar', 'test');
jQuery.data(元素,键,值)
元素
钥匙
价值
在你的情况下,你有element
,key
但你错过了value