Javascript 具有相同类别的特定项目的褪色背景色

Javascript 具有相同类别的特定项目的褪色背景色,javascript,jquery,laravel,Javascript,Jquery,Laravel,我有这段代码,我用同一个类填充来自数据库的帖子。这将产生多个{{$post->body}}这个精确的3秒发光高亮显示消息的功能作为高亮显示效果在jqueryui中实现 颜色和持续时间是可变的 示例代码使用高光效果切换div <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>highlight demo</title>

我有这段代码,我用同一个类填充来自数据库的帖子。这将产生多个

{{$post->body}}这个精确的3秒发光高亮显示消息的功能作为高亮显示效果在jqueryui中实现

颜色和持续时间是可变的

示例代码使用高光效果切换div

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>highlight demo</title>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
    <style>
    #toggle {
        width: 100px;
        height: 100px;
        background: #ccc;
    }
    </style>
    <script src="//code.jquery.com/jquery-1.12.4.js"></script>
    <script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>

    <p>Click anywhere to toggle the box.</p>
    <div id="toggle"></div>

    <script>
    $( document ).click(function() {
        $( "#toggle" ).toggle( "highlight" );
    });
    </script>

</body>
</html>
您可以使用CSS进行操作,并且只能使用JavaScript添加/删除类。例如,考虑下面的代码片段。当然,你可以根据自己的喜好改变时间。也可以以各种方式进行背景转换

$'.post'。单击,函数{ var$post=$this; $post.addClass'highlight'; setTimeoutfunction{$post.removeClass'highlight';},400; }; .邮政{ 显示:内联块; 垂直对齐:顶部; 宽度:100px; 高度:100px; 利润率:10px; 填充:20px; 背景色:fff; 边框:1px实心444; 文本对齐:居中; 过渡:背景色。3s; } .post.highlight{ 背景色:ffb457; } 点击我! 或者我!
或者我,也许…我找到了解决问题的办法。我错过了这个。我刚刚将这行代码添加到我当前的js中

$(postBodyElement).effect("highlight", {color: '#eff0f1'}, 5000);
这是我最后的代码:

var postBodyElement = event.target.parentNode.parentNode.childNodes[1];
$('#modal-save').on('click', function() {
$.ajax({
    method: 'POST',
    url: url,
    data: {body: $('#post-body').val(), postId: postId, _token: token}
})
.done(function (msg) {
    //console.log(JSON.stringify(msg));
    $(postBodyElement).text(msg['new_body']);
    $(postBodyElement).effect("highlight", {color: '#eff0f1'}, 5000);
    $('#edit-modal').modal('hide');
});
});

此代码将更改我页面中的所有相同类。这将更改我页面中的所有相同类。不,不会。我已经编辑了我的帖子来展示这个。谢谢你。我试试这种方法。
$(postBodyElement).effect("highlight", {color: '#eff0f1'}, 5000);
var postBodyElement = event.target.parentNode.parentNode.childNodes[1];
$('#modal-save').on('click', function() {
$.ajax({
    method: 'POST',
    url: url,
    data: {body: $('#post-body').val(), postId: postId, _token: token}
})
.done(function (msg) {
    //console.log(JSON.stringify(msg));
    $(postBodyElement).text(msg['new_body']);
    $(postBodyElement).effect("highlight", {color: '#eff0f1'}, 5000);
    $('#edit-modal').modal('hide');
});
});