html binding属性,html binding

The "html" binding

Purpose

The html binding causes the associated DOM element to display the HTML specified by your parameter.

Typically this is useful when values in your view model are actually strings of HTML markup that you want to render.

Example

var viewModel = {

details: ko.observable() // Initially blank

};

viewModel.details("For further details, view the report here."); // HTML content appears

Parameters Main parameter

KO clears the previous content and then sets the element’s content to your parameter value using jQuery’s html function or by parsing the string into HTML nodes and appending each node as a child of the element, if jQuery is not available.

If this parameter is an observable value, the binding will update the element’s content whenever the value changes. If the parameter isn’t observable, it will only set the element’s content once and will not update it again later.

If you supply something other than a number or a string (e.g., you pass an object or an array), the innerHTML will be equivalent to yourParameter.toString()

Additional parameters None

Note: About HTML encoding

Since this binding sets your element’s content using innerHTML, you should be careful not to use it with untrusted model values, because that might open the possibility of a script injection attack. If you cannot guarantee that the content is safe to display (for example, if it is based on a different user’s input that was stored in your database), then you can use the text binding, which will set the element’s text value using innerText or textContent instead.

Dependencies

None, other than the core Knockout library.

© Steven Sanderson, the Knockout.js team, and other contributors

Licensed under the MIT License.

http://knockoutjs.com/documentation/html-binding.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值