如何经常更改textarea的边框颜色? [英] How to change the border color of a textarea frequently ?

查看:683
本文介绍了如何经常更改textarea的边框颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过javascript频繁更改textarea的边框颜色?

How I can change the border color of the textarea frequently by javascript ?

推荐答案

您可以使用 setInterval() N 毫秒更改边框颜色。将所需的所有颜色存储在数组中,并在更改颜色时始终选择下一个元素,并在没有元素时返回第一个元素。

You can use setInterval() to change the border color every N milliseconds. Store all colors you want in an array, and always pick the next element when changing the color, and go back to the first element when there are no elements left.
var milliseconds = 2000; // 2 seconds
var colors = ["red", "green", "blue"]; // add more if you want
var currentIndex = 0;
setInterval(function () {
    var newColor = colors[currentIndex];
    document.getElementById("yourArea").style.borderColor = newColor;
    currentIndex++;
    if (currentIndex >= colors.length) {
        currentIndex = 0;
    }
}, milliseconds);


这篇关于如何经常更改textarea的边框颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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