jQuery数据方法返回整数而不是字符串

jQuery data method returns integer instead of string

本文关键字:字符串 整数 数据 方法 返回 jQuery      更新时间:2023-09-26

HTML

<div class="ui-droppable" data-number="P"></div>

JS来源检查

div.ui-droppable
|...
|--attributes:NamedNodeMap
|  |...
|  |--data-number
|  |  |...
|  |  |--nodeValue: "P"
|  |  |...
|  |  |--textContent: "P"
|  |  |--value: "P"
|  |  |...
|  |...
|
|--dataset:DOMStringMap
|  |
|  |--number: "P"
   |...

jQuery

但是

$(this).data('number');

给我一个整数1。如何使用data方法获得P

您没有绑定数据。您可以通过以下方式访问该数据编号:

$(this).attr('data-number');