最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery data() type conversion issue? - Stack Overflow

programmeradmin1浏览0评论

I have the following div <div data-item-id="0234"> and when I try to access the data with $element.data("itemId") jQuery converts it to int and now i get 234 instead of "0234". Is there any way i can get the actual data "0234" ?

I have the following div <div data-item-id="0234"> and when I try to access the data with $element.data("itemId") jQuery converts it to int and now i get 234 instead of "0234". Is there any way i can get the actual data "0234" ?

Share Improve this question edited Jun 14, 2012 at 6:27 Engineer 48.9k12 gold badges90 silver badges92 bronze badges asked Jun 11, 2012 at 16:14 danielsdaniels 19.3k34 gold badges109 silver badges174 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 5

Simply use .attr instead ($element.attr('data-item-id');). The docs themselves suggest this.

Try this:

$element.attr("data-item-id")

Using attr: http://jsbin./ipuhah/

$(selector).attr("data-item-id");
发布评论

评论列表(0)

  1. 暂无评论