IE色彩处理过程
添加时间: 2005-6-9 5:04:11 作者: 网络收集 阅读次数:60 来源: http://d9soft.com
Internet Explorer 是怎样处理不合法的颜色代码的呢?
<input id=test value='blueidea'><input type=button value=ok onclick=alert(colVal(test.value))>
<script>
function colVal(str)
{
var clen, cstr = rgbstr = ""
// 将无效字符转成"0"
str = str.replace(/[^0-9a-f]/g, "0")
// 如果字符串不满3位或6位,字符串在后面补"0"
while(str.length != 3 && str.length < 6) str += "0"
// 将3位色彩值,转为6位色彩值
if (str.length == 3) str = str.replace(/(.)/g, "0$1")
// 取表示RGB字符串的长度
clen = Math.ceil(str.length/3)
// 如果RGB字符串长度大于2,进行去位处理
if (clen > 2)
{
for (var i=0; i<3; i++)
{
// 取得表示Red、Green 或 Blue的字符串
rgbstr = str.substr(i*clen, clen)
// 取RGB字符串的后8位的前2位
cstr += rgbstr.substr(clen-8, 2)
}
str = cstr
}
return str
}
</script>
上一篇文章: 提高你的DHTML性能 下一篇文章: 标记语言处理模型(演示版)
相关文章:

