Knockoutjs HTML bindings are the same as text, except that HTML is used to insert HTML code, and text is used to insert text. It can be understood that HTML used the Innerhtml,text to use innertext.
Examples of HTML usage:
| The code is as follows |
Copy Code |
<div data-bind= "Html:details" ></div>
<script type= "Text/javascript" > var ViewModel = { Details:ko.observable ()//default is empty }; Viewmodel.details ("<em style= ' color:red ' > Shrimp Tiger Fish </em>"); What the DIV displays </script>
|
What you need to be aware of: knockout converts the parameter params passed into viewmodel.details (params) to a string and replaces the contents of the bound element, using params.tostring () Convert to string and then use innerHTML, so:
| The code is as follows |
Copy Code |
If params is [' a ', {a: ' B '},function () {}] The result is: A,[object object],function () {}; If params is {a: ' B '} The result is: [Object]; If params is a function () {return ' 123 ';} The result is: function () {return ' 123 ';} |