Heim  >  Fragen und Antworten  >  Hauptteil

javascript - Wie spezifiziere ich eine Funktionsfunktion im Datenattribut von HTML5?

Kann ich im data-*-Attribut eine Funktion angeben?

Wenn ich zum Beispiel so schreibe, erhalte ich die Fehlermeldung „Formatierer ist keine Funktion:

“.
<th  data-formatter="test3(value, row, index)">field_name_cn</th>
学习ing学习ing2674 Tage vor1003

Antworte allen(6)Ich werde antworten

  • 迷茫

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

    eval一下就可以了,但是觉得你这个方式解决问题不太合理,不如说出你的需求,看看有没有好的解决方案

    Antwort
    0
  • 阿神

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

    is not function:is string

    Antwort
    0
  • typecho

    typecho2017-06-24 09:45:53

    不能.data-属性依然是属性,其值只是字符串.

    函数可以转成字符串, 但就失去了函数的特性了当然

    Antwort
    0
  • 阿神

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

    话说可以eval一把,把字符串当作函数代码来执行

    Antwort
    0
  • 代言

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

    但是如果你用vue或者react框架的话可以解决你这一点。但是这是单纯的html,是不行的

    Antwort
    0
  • 黄舟

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

    好奇你想做什么?

    Antwort
    0
  • StornierenAntwort