Custom attributes - Yea or nay?

前端 未结 14 2072
南旧
南旧 2020-11-22 03:02

Recently I have been reading more and more about people using custom attributes in their HTML tags, mainly for the purpose of embedding some extra bits of data for use in ja

14条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 03:44

    Embed the data in the dom and use metadata for jQuery.

    All the good plug-ins support the metadata plugin(allowing per tag options).

    It also allows infinitely complex data/data structures, as well as key-value pairs.

  • ...
  • OR

  • ...
  • OR

  • ...
  • Then get the data like so:

    var data = $('li.someclass').metadata();
    if ( data.some && data.some == 'random' )
    alert('It Worked!');
    

提交回复
热议问题