【问题标题】:Compare two text and find the difference比较两个文本并找出差异
【发布时间】:2017-12-11 08:50:31
【问题描述】:

我正在开发 AngularJS 应用程序,我想比较文本并突出显示另一个 div 中的差异。下面是我的代码

$scope.left="one two three";
$scope.right="one two four";

<div>{{diff}}</div>

在上面的上下文中,如果我们比较两个作用域的左右,我们会知道“三”在 $scope.left 中是多余的,而“四”在 $scope.right 中是多余的。所以我们需要用红色突出“三”,用绿色突出“四”,这样就很容易找到区别。

我可以使用任何插件或库来实现此功能吗?

【问题讨论】:

标签: jquery angularjs angularjs-directive angularjs-scope


【解决方案1】:

我知道一个很好的库 jsdiff:https://github.com/kpdecker/jsdiff

一个简单的例子:http://incaseofstairs.com/jsdiff/

这是你要找的吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-19
    相关资源
    最近更新 更多