HTML:
<html>
<body>
<textarea>Original Text</textarea>
<button>Replace</button>
</body>
</html>
jQuery:
$(function() {
$('button').click(function () {
$('body').html($('body').html().replace('Original','New'));
});
});
我可以用褪色的黄色背景以某种方式突出显示更改吗?
最佳答案
正如 Sarfraz 所说,使用 jQuery 颜色插件。用法与jQuery中的animate方法相同。该插件覆盖以下属性的动画方法:'backgroundColor'、'borderBottomColor'、'borderLeftColor'、'borderRightColor'、'borderTopColor'、'color'、'outlineColor'。
jQuery animate 方法的使用和信息可以在这里找到:http://api.jquery.com/animate/
此外,如果您想替换 HTML 中的某些内容,最好获取包含您想要调用替换方法的内容的标签的包装标签,而不是作为字符串搜索整个正文。通常你会使用:
$('#idOfMyWrapperTag').html().replace('this', 'that')
但是由于您使用的是文本区域,您可以通过以下方式获取它的值:
$('textarea').val().replace('this', 'that');
..弗雷德里克
关于javascript - 突出显示变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2863641/