4

这个代码显示了非换空间转义序列,而不是实际的空间:如何防止knockout.js数据绑定中的字符溢出?

<html> 
    <head> 
    <script src="../js/jquery.min.js"></script> 
    <script src="../js/knockout-2.2.1.js"></script> 
    <script> 
     $(document).ready(function() { 
     var modelType = function() { 
      this.A = ko.observable('a b&nbsp;&nbsp;c'); 
     }; 
     var model = new modelType(); 
     ko.applyBindings(model); 
     }); 
    </script> 
    </head> 
    <body> 
    <p data-bind="text: A"></p> 
    </body> 
</html> 

它显示以下内容:

a b&nbsp;&nbsp;c 

代替

a b c 

如何预防这种行为?

回答

10

,您应该使用html结合,而不是text

<p data-bind="html: A"></p> 
+0

和期权? 'ie ' –

+0

@ e10你有没有发现如何做这个选项? – DasBeasto