この記事では、JavaScriptのRGBに16進数を実装する方法について説明します。参照のためにそれを共有してください。特定の実装方法は次のとおりです。
次のようにコードをコピーします。<
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<Meta http-equiv = "content-type" content = "text /html; charset = utf-8" />
<title> rgb </title>の16進数</title>
<style>
*{マージン:0;パディング:0; font-family: 'Microsoft yahei'}
.replace {width:400px; height:210px; margin:0 auto; padding-top:40px;}
.title {text-align:center; display:block}
フォーム{幅:200px;マージン:30px auto;}
input {outline:none;}
input [type = "button"] {cursor:pointer;}
</style>
<スクリプト>
function hextor(h){
parseintを返す((cuthex(h))。サブストリング(0、2)、16)
}
function hextog(h){
parseintを返す((cuthex(h))。サブストリング(2、4)、16)
}
function hextob(h){
parseint((cuthex(h))。サブストリング(4、6)、16)を返す
}
function cuthex(h){
H.Charat(0)== "#"を返しますか? H.Substring(1、7):h
}
関数setbgcolorbyid(id、scolor){
var Elems;
if(document.getElementById){
if(elems = document.getElementbyId(id)){
if(elems.style)elems.style.backgroundcolor = scolor;
}
}
}
</script>
</head>
<body>
<div>
<span> javascriptネイティブヘキサデシマルの色値RGB値</span>
<form name = "rgb">
<入力値= "ffffffff" maxlength = "7" size = "16" name = "hex" />
<入力onclick = "setbgcolorbyid( 'colrsampe'、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 =" convert "type =" button "name =" btn "/>
<br /> <br />
R:<入力サイズ= "3" name = "r" />
G:<入力サイズ= "3" name = "g" />
B:<入力サイズ= "3" name = "b" />
</form>
</div>
</body>
</html>
操作効果は、次の図に示されています。
この記事がみんなのJavaScriptプログラミングに役立つことを願っています。