标签:
<body> <input type="text" value="test" onclick="flash(this)"> </body> <script> function flash(elem){ var elem = typeof elem === ‘string‘ ? document.getElementById(elem) : elem, // 参数可接收id或者元素本身 borderColor = elem.style.borderColor elem.style.borderColor = borderColor == ‘red‘ ? elem.borderColor : ‘red‘ if (!elem.timer) { elem.times = 6 elem.borderColor = borderColor // 保存元素原来的边栏样式 elem.timer = setInterval(function() { flash(elem) }, 180) // 这里直接以元素当做参数, 提升执行效率 } else { if (elem.times == 0) { clearInterval(elem.timer) elem.timer = null } elem.times-- } } </script>
标签:
原文地址:http://www.cnblogs.com/duwenlei/p/4313665.html