使用敲除绑定时,HTML实体(®,©,€等)无法正确显示。
HTML code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<!-- This is a *view* - HTML markup that defines the appearance of your UI -->
<!--Data appearing via binding-->
<p>Product name: <strong data-bind="text: productName"></strong></p>
<!--Static data-->
<p>Product name:<strong>ABC®EFG</strong></p>
<script src="js/jquery-3.1.0.min.js"></script>
<script type="text/javascript" src="js/knockout-3.4.0.js"></script>
<script src="js/script.js" charset="utf-8"></script>
</body>
</html>
的Javascript(的script.js):
function AppViewModel() {
this.productName = ko.observable("ABC®EFG");
}
// Activates knockout.js
ko.applyBindings(new AppViewModel());
输出:
答案 0 :(得分:0)
将绑定从text
更改为html
解决了问题。
<p>Product name: <strong data-bind="html: productName"></strong></p>