【问题标题】:jQuery .data can access camel case key using dashjQuery .data 可以使用破折号访问骆驼大小写键
【发布时间】:2014-08-20 19:28:05
【问题描述】:

谁能解释一下为什么会这样: $('#someId').data('typeId', 2); $('#someId').data('type-id'); // will return 2

这也是小提琴:http://jsfiddle.net/L6nLpgdb/

谢谢!

【问题讨论】:

  • 阅读 html5 dataset - for any dash (U+002D) followed by an ASCII lowercase letter a to z, the dash is removed and the letter is transformed into its uppercase counterpart; - 因为规范是这样写的

标签: javascript jquery


【解决方案1】:

检查这个link

The custom data attributes is transformed to a key for the DOMStringMap entry with the following rules:

    any dash (U+002D) is removed;
    any letter following a dash (U+002D), before its removal, is set in its uppercase counterpart.

【讨论】:

    猜你喜欢
    • 2018-11-13
    • 1970-01-01
    • 2014-06-23
    • 2012-01-06
    • 2013-07-16
    • 2020-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多