【发布时间】:2013-02-03 03:32:56
【问题描述】:
我们遇到这种“奇怪”的情况,当在 jquery click 函数中检索时,存储在数据属性(例如 data-prodcode)中的某些产品代码(例如 11E6)被转换为 11000000。像这样的:
<a data-prodcode="11E6">click</a>
var code = $(this).data('prodcode');
console.log(code); --> 11000000
关于如何避免这种行为或可能导致这种行为的任何建议?
【问题讨论】:
-
这是因为
.data会尽可能将值自动转换为数字或布尔值,而字符串11E6在计算机上看起来就像a number in scientific notation。
标签: javascript jquery custom-data-attribute jquery-data