Home  >  Q&A  >  body text

javascript - How to specify a function function in the data attribute of html5?

Can I specify a function function in the data-* attribute?

For example, if I write like this, I will get an error formatter is not a function:

<th  data-formatter="test3(value, row, index)">field_name_cn</th>
学习ing学习ing2674 days ago1002

reply all(6)I'll reply

  • 迷茫

    迷茫2017-06-24 09:45:53

    Eval is enough, but I think your way of solving the problem is unreasonable. Why not tell us your needs and see if there is a good solution

    reply
    0
  • 阿神

    阿神2017-06-24 09:45:53

    is not function:is string

    reply
    0
  • typecho

    typecho2017-06-24 09:45:53

    No.data-attribute is still an attribute, its value is just a string.

    The function can be converted into a string, but of course it loses the characteristics of the function

    reply
    0
  • 阿神

    阿神2017-06-24 09:45:53

    Speaking of which, you can eval and execute the string as a function code

    reply
    0
  • 代言

    代言2017-06-24 09:45:53

    But if you use vue or react framework, you can solve this problem. But this is pure html, it won’t work

    reply
    0
  • 黄舟

    黄舟2017-06-24 09:45:53

    Curious what do you want to do?

    reply
    0
  • Cancelreply