【问题标题】:compare and mark word in strings with JS用JS比较和标记字符串中的单词
【发布时间】:2018-03-10 02:47:39
【问题描述】:

需要帮助,我想比较并标记这个词像这张图片

https://i.stack.imgur.com/Ffdml.png

我尝试使用 js,但没有成功

<div class="form-group">
    <div class="col-md-6">
        <section class="form-group-vertical">
            <input class="form-control" type="text" id="1">
        </section>
    </div>
    <div class="col-md-6" id="notif">
        <section class="form-group-vertical">
            <input class="form-control" type="text" id="2" >
        </section>
    </div>
</div>

<script type="text/javascript">
$(document).ready(function()
{

    var firstInput = $('#1');
    var seconInput = $('#2');

    var aa = $('#2');
    aa.change(function() {
    var n = firstInput.val().localeCompare(seconInput.val());

        if ( n === 0 ) {
            console.log('ok');
            $('#notif').attr('class', 'col-md-6');

        }
        else{
            console.log('ko');
            $('#notif').attr('class', 'has-error col-md-6');

        }
    });

});
</script>

有什么建议吗?

【问题讨论】:

  • 这是一个php问题吗?没有任何东西使问题不清楚。为什么在我编辑后又添加回来?
  • 对不起.. 我应该删除 php 标签吗?
  • 如果没有相关性/代码,那么它会误导那些关注该标签的人,比如我也这样做。
  • js/jquery 不是我的包(我知道一些),但我只能说:检查您的开发者控制台并确保您已加载 jquery 库。
  • 我确实使用了 jquery lib,谢谢兄弟

标签: javascript jquery html


【解决方案1】:

简单的解决方法请使用这个kpdecker/jsdiff

在线演示: demo

【讨论】:

    猜你喜欢
    • 2021-05-09
    • 2016-06-10
    • 1970-01-01
    • 1970-01-01
    • 2019-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多