Knockoutjs of HTML binding method

Source: Internet
Author: User

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 ';}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.