16进制颜色值转RGBjs特效

来源:https://www.sucaihuo.com/js/1819.html 2017-04-25 18:42浏览(330) 收藏

这是一款简单的16进制颜色值转RGBjs特效,推荐给大家
16进制颜色值转RGBjs特效
分类:css3 > table 难易:
查看演示 下载资源 下载积分: 20 积分

16进制颜色值转RGB值

<div class="replace">
        		<span class="title">16进制颜色值转RGB值</span>
     			<form name="rgb">
     				<input value="ffffff" maxlength="7" size="16" name="hex">
               <input onClick="setBgColorById('colorSample',this.form.hex.value);
               this.form.r.value=hexToR(this.form.hex.value);
               this.form.g.value=hexToG(this.form.hex.value);
               this.form.b.value=hexToB(this.form.hex.value);" value="转换" type="button" name="btn">
               <br><br>
              	 R:<input style="width:30px" size="3" name="r">
                G:<input style="width:30px" size="3" name="g">
                B:<input style="width:30px" size="3" name="b">
     			</form>  			  
        	</div>

几句简单的js代码

function hexToR(h) {
            return parseInt((cutHex(h)).substring(0, 2), 16)
        }
        function hexToG(h) {
            return parseInt((cutHex(h)).substring(2, 4), 16)
        }
        function hexToB(h) {
            return parseInt((cutHex(h)).substring(4, 6), 16)
        }
        function cutHex(h) {
            return h.charAt(0) == "#" ? h.substring(1, 7) : h
        }
        function setBgColorById(id, sColor) {
            var elems;
            if (document.getElementById) {
                if (elems = document.getElementById(id)) {
                    if (elems.style) elems.style.backgroundColor = sColor;
                }
            }
         }
评论0
头像

系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 1915635791

1 2