Single quotes in data attribute containing json

前端 未结 5 1406
清酒与你
清酒与你 2021-02-12 21:06

Cosmetic question: I have a html element containing possible dimensions for some embedded images, these are stored as:

5条回答
  •  清歌不尽
    2021-02-12 22:01

    You can use " instead of ". But quoting orgies are horrible (in HTML even more than in PHP) so better go with single-quoting your html attributes.

    BTW, you do not need to use .parseJSON - jQuery does that automatically if the data- attribute starts with { (actually, it's more complex - here's the regex it uses to test if it should be parsed as JSON: ^(?:\{.*\}|\[.*\])$).

提交回复
热议问题