html “data-” attribute as javascript parameter

前端 未结 6 932
说谎
说谎 2020-11-29 00:27

Lets say I have this:

6条回答
  •  爱一瞬间的悲伤
    2020-11-29 01:24

    you might use default parameters in your function and then just pass the entire dataset itself, since the dataset is already a DOMStringMap Object

    that way, you can deal with any data-values that got set in the html tag, or use defaults if they weren't set - that kind of thing

    maybe not in this situation, but in others, it might be advantageous to put all your preferences in a single data-attribute

    there are probably more terse ways of doing that, if you already know certain things about the order of the data

提交回复
热议问题