gpt4 book ai didi

jquery - 数据属性变为整数

转载 作者:行者123 更新时间:2023-12-03 21:43:59 26 4
gpt4 key购买 nike

看看这个简单的例子 on jsfiddle

<div id ="a" data-siteid="00005">00005 turns into:</div>
<div id="b" data-siteid="S00005">S00005 turns into: </div>

代码

$('#a').append($('#a').data("siteid"));
$('#b').append($('#b').data("siteid"));

​结果

00005 turns into:5
S00005 turns into: S00005

我想返回“00005”和“S00005”。

最佳答案

尝试

$('#a').append($('#a').attr('data-siteid'));
$('#b').append($('#b').attr('data-siteid'));

From the jQuery Docs

Every attempt is made to convert the string to a JavaScript value (this includes booleans, numbers, objects, arrays, and null) otherwise it is left as a string. To retrieve the value's attribute as a string without any attempt to convert it, use the attr() method.

关于jquery - 数据属性变为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10296985/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com