jQuery 1.8是否改变了.data()返回值的方式? [英] Has jQuery 1.8 changed how .data() returns the value?

查看:73
本文介绍了jQuery 1.8是否改变了.data()返回值的方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相关问题:停止转换 jQuery .data()

Related question: Stop jQuery .data() from converting

根据 .data()的文档


每次尝试都将字符串转换为JavaScript值
(这包括布尔值,数字,对象,数组和null),否则
将其保留为字符串。要将值的属性检索为字符串
而不尝试转换它,请使用attr()方法

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 1.7.2是正确的,但1.8.2不进行转换。这是新的预期行为吗?

This is true for jQuery 1.7.2, but 1.8.2 does not do the conversion. Is this the new expected behavior?

例如,使用HTML < div data-code-name =007> Bond, James< / div>

For example, with the HTML <div data-code-name="007">Bond, James</div>

jQuery v1.7.2
$(div)。data( codeName)返回7
示例: http://jsfiddle.net/ dMHS4 /

jQuery v1.7.2 $("div").data("codeName") returns 7 Example: http://jsfiddle.net/dMHS4/

jQuery v1.8.2
$(div)。data(codeName)返回007
示例: http://jsfiddle.net/dMHS4/ 2 /

jQuery v1.8.2 $("div").data("codeName") returns "007" Example: http://jsfiddle.net/dMHS4/2/

推荐答案

我认为这回答了你的问题

I think this answers your question

http://bugs.jquery.com/ticket/7579

他们还有一个测试小提琴 http://jsfiddle.net/dmethvin/8SsWK /

They also have a test fiddle http://jsfiddle.net/dmethvin/8SsWK/

并且它显示如果转换为数字将其从1.0更改为1,那么它现在被视为字符串,而不是数字。如果你在1.7.2和1.8.2

And it shows that if converting to a number changed it from say 1.0 to 1, then it now is treated as a string, instead of a number. You can see this difference if you run there tests in 1.7.2 vs 1.8.2

这篇关于jQuery 1.8是否改变了.data()返回值的方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆