Best way to store JSON in an HTML attribute?

后端 未结 9 1533
梦毁少年i
梦毁少年i 2020-11-30 19:57

I need to put a JSON object into an attribute on an HTML element.

  1. The HTML does not have to validate.

    Answered by Quenti

9条回答
  •  误落风尘
    2020-11-30 20:21

    You can use knockoutjs,

    First name: todo

    Last name: todo

    knockout.js

    // This is a simple *viewmodel* - JavaScript that defines the data and behavior of your UI
    function AppViewModel() {
        this.firstName = "Jayson";
        this.lastName = "Monterroso";
    }
    
    // Activates knockout.js
    ko.applyBindings(new AppViewModel());
    

    Output

    First name: Jayson Last name: Monterroso

    Check this: http://learn.knockoutjs.com/

提交回复
热议问题