突出变化? [英] Highlight changes?

查看:69
本文介绍了突出变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML:

<html>
<body>
    <textarea>Original Text</textarea>
    <button>Replace</button>
</body>
</html>

jQuery:

$(function() {
 $('button').click(function () {
     $('body').html($('body').html().replace('Original','New'));
 });
});

http://jsfiddle.net/r7MgY/

我可以用淡黄色背景以某种方式突出显示变化吗?

Can I highlight changes somehow with a fading yellow background maybe?

推荐答案

正如Sarfraz所说,使用jQuery颜色插件。用法与jQuery中的animate方法相同。该插件会覆盖这些属性的动画方法:'backgroundColor','borderBottomColor','borderLeftColor','borderRightColor','borderTopColor','color','outlineColor'。

As Sarfraz says, use the jQuery color plugin. Usage is the same as animate method in jQuery. The plugin overrides the animation methods for these properties: 'backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'.

jQuery动画方法的使用和信息可以在这里找到: http://api.jquery.com/animate /

jQuery animate method usage and info can be found here: http://api.jquery.com/animate/

另外,如果要替换HTML中的内容,最好获取包含要调用替换方法的标记的包装标记而不是作为一个字符串搜索整个身体。通常你会使用:

Also, if you want to replace something in the HTML it's better to get the wrapper tag of the tag that contains what you want invoke the replace method on instead of search through the entire body as a string. Normally you'd use:

$('#idOfMyWrapperTag').html().replace('this', 'that')

但由于你使用的是textarea,你可以用它来获得它的价值:

But since you are using a textarea you can get it's value with this:

$('textarea').val().replace('this', 'that');

.. fredrik

..fredrik

这篇关于突出变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆