css 进制转换

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link id='link1' rel="stylesheet" type="text/css" />
        <script>
            function hf1(ojb){
                ojb=document.getElementById('r');
                ojb.style.background='hotpink';
            }
            function hf2(ojb){
                ojb=document.getElementById('r');
                ojb.style.background='navajowhite';
            }
        </script>
    </head>
    <body>
        
        <form id="a">
            <table id='r'>
                <td><strong>可以换皮肤哦</strong></td>
                <td><input id="bot1" type="button" value="皮肤1" οnclick="hf1(this)"/> </td>
                <td> <input id="bot2" type="button" value="皮肤2" οnclick="hf2(this)"/></td>
                <tr>
                <td>输入姓名</td>
                <td> <input type="text"  name="xm" value="name"/><br /></td>
               </tr>
               <tr>
                <td>输入密码</td>
                <td><input type="password" name='mm' value="mm" /><br /></td>
               </tr>
              <tr>
                <td>请您留言</td>
                <td><textarea></textarea> </td>
            </tr>
            <tr>
                <td><input type="submit" value="提交" /></td>
            </tr>
            
            
            </table>
        
        </form>
    </body>
</html>

 

 

加法拼串  例如:var a='10'+2    输出等于102

var yu=70;
document.write(yu);
yu=parseInt(yu,16);//控制进制转换为哪个进制    把yu转换为16进制的
console.log(yu);

          zx="255.98";
          console.log(parseInt(zx));
          zx=true;//true -->"true" -->NaN
          console.log(parseInt(zx));
          zx=null;//NaN
          console.log(parseInt(zx));
          var hhy;//NaN
          console.log(parseInt(hhy));//NaN
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是 TypeScript 实现 sRGBA 色值进制转换的示例代码: ```typescript class SrgbaColor { constructor(public r: number, public g: number, public b: number, public a: number) {} // 将 sRGBA 换为 RGBA toRgba(): RgbaColor { const r = Math.round(this.r * this.a + 255 * (1 - this.a)); const g = Math.round(this.g * this.a + 255 * (1 - this.a)); const b = Math.round(this.b * this.a + 255 * (1 - this.a)); const a = this.a; return new RgbaColor(r, g, b, a); } // 将 sRGBA 换为十六进制字符串 toHexString(): string { const r = Math.round(this.r * this.a + 255 * (1 - this.a)); const g = Math.round(this.g * this.a + 255 * (1 - this.a)); const b = Math.round(this.b * this.a + 255 * (1 - this.a)); const a = Math.round(this.a * 255); const hexR = r.toString(16).padStart(2, '0'); const hexG = g.toString(16).padStart(2, '0'); const hexB = b.toString(16).padStart(2, '0'); const hexA = a.toString(16).padStart(2, '0'); return `#${hexR}${hexG}${hexB}${hexA}`; } // 将 sRGBA 换为 CSS 格式的字符串 toCssString(): string { const r = Math.round(this.r * this.a + 255 * (1 - this.a)); const g = Math.round(this.g * this.a + 255 * (1 - this.a)); const b = Math.round(this.b * this.a + 255 * (1 - this.a)); const a = this.a; return `rgba(${r}, ${g}, ${b}, ${a})`; } } class RgbaColor { constructor(public r: number, public g: number, public b: number, public a: number) {} // 将 RGBA 换为 sRGBA toSrgba(): SrgbaColor { const alpha = this.a; const r = this.r / 255; const g = this.g / 255; const b = this.b / 255; const max = Math.max(r, g, b); const min = Math.min(r, g, b); const chroma = max - min; let s = 0; if (chroma > 0) { s = chroma / max; } const v = max; const a = alpha; const l = (max + min) / 2; const gamma = 2.2; const lsrgb = l ** gamma; const vsrgb = v ** gamma; const m = (lsrgb + vsrgb) / 2; const msrgb = m ** (1 / gamma); let rSrgb = 0; let gSrgb = 0; let bSrgb = 0; if (chroma > 0) { const c = (vsrgb - lsrgb) / chroma; const h = (() => { if (r === max) { return (g - b) / chroma; } else if (g === max) { return 2 + (b - r) / chroma; } else { return 4 + (r - g) / chroma; } })(); const hDegrees = h * 60; const hRadians = (hDegrees * Math.PI) / 180; const x = chroma * (1 - Math.abs((h % 2) - 1)); if (hDegrees >= 0 && hDegrees < 60) { rSrgb = vsrgb; gSrgb = x + lsrgb; bSrgb = lsrgb; } else if (hDegrees >= 60 && hDegrees < 120) { rSrgb = x + lsrgb; gSrgb = vsrgb; bSrgb = lsrgb; } else if (hDegrees >= 120 && hDegrees < 180) { rSrgb = lsrgb; gSrgb = vsrgb; bSrgb = x + lsrgb; } else if (hDegrees >= 180 && hDegrees < 240) { rSrgb = lsrgb; gSrgb = x + lsrgb; bSrgb = vsrgb; } else if (hDegrees >= 240 && hDegrees < 300) { rSrgb = x + lsrgb; gSrgb = lsrgb; bSrgb = vsrgb; } else if (hDegrees >= 300 && hDegrees < 360) { rSrgb = vsrgb; gSrgb = lsrgb; bSrgb = x + lsrgb; } } else { rSrgb = v; gSrgb = v; bSrgb = v; } const r = rSrgb ** (1 / gamma); const g = gSrgb ** (1 / gamma); const b = bSrgb ** (1 / gamma); return new SrgbaColor(r, g, b, a); } // 将 RGBA 换为十六进制字符串 toHexString(): string { const hexR = this.r.toString(16).padStart(2, '0'); const hexG = this.g.toString(16).padStart(2, '0'); const hexB = this.b.toString(16).padStart(2, '0'); const hexA = Math.round(this.a * 255) .toString(16) .padStart(2, '0'); return `#${hexR}${hexG}${hexB}${hexA}`; } // 将 RGBA 换为 CSS 格式的字符串 toCssString(): string { return `rgba(${this.r}, ${this.g}, ${this.b}, ${this.a})`; } } ``` 使用示例: ```typescript const srgba = new SrgbaColor(0.2, 0.3, 0.4, 0.5); const rgba = srgba.toRgba(); // RGBA {r: 77, g: 115, b: 153, a: 0.5} const hex = srgba.toHexString(); // "#4d739980" const css = srgba.toCssString(); // "rgba(77, 115, 153, 0.5)" ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值