gpt4 book ai didi

javascript - Angular 字符编码问题 contenteditable div

转载 作者:行者123 更新时间:2023-11-30 16:25:53 25 4
gpt4 key购买 nike

我正在结合使用 Angular 和 contenteditable div 来尝试创建双向绑定(bind),稍后我可以使用 Angular Controller 来操作数据。除了进入模型的某些 html 字符外,一切都运行良好。

例如,当我输入 & 我得到 & 当有一个不间断的空格时我得到 nbsp;

如何修改 contenteditable 指令以清除编码值并仅保留未编码版本?

Plunkr 在这里 - http://plnkr.co/edit/ToylycanYcMJq15K36Yd?p=preview

你会在 contenteditable 指令中看到我有这一行:
html = element.html().replace(' ','');

尝试替换   值,但没有任何影响...

最佳答案

尽管您可以执行类似 this 的操作,但我认为您最好使用 inputtextarea 来实现。根据docs AngularJS 模型仅支持 inputselecttextarea

还有一个 open问题与您面临的问题相同。

如果您打算使用 contenteditable div,这里是代码:

var myApp = angular.module('app',[]);

myApp.controller('chatterCtrl', ['$scope', function($scope) {
$scope.$watch('comment', function(){
if($scope.comment != undefined){
$scope.comment = unescape($scope.comment);
}
}, true);
}]);

关于javascript - Angular 字符编码问题 contenteditable div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34147208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com