龙空技术网

JavaScript的构造函数方法

孤帆月下 235

前言:

现在姐妹们对“数据结构及算法js”大致比较关心,小伙伴们都想要剖析一些“数据结构及算法js”的相关知识。那么小编在网摘上收集了一些对于“数据结构及算法js””的相关内容,希望看官们能喜欢,你们快快来学习一下吧!

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>构造函数</title>

</head>

<style>

#div010{

background: black;

}

#div01{

text-align: center;

font-size: 20px;

font-family: '楷体';

line-height: 70px;

color: aliceblue;

width: 70px;

height: 70px;

border-radius: 50%;

border: 20px solid steelblue

}

#div02{

text-align: center;

font-size: 20px;

font-family: '楷体';

line-height: 70px;

color: aliceblue;

width: 70px;

height: 70px;

border-radius: 50%;

border: 20px solid silver

}

#div03{

text-align: center;

font-size: 20px;

font-family: '楷体';

line-height: 70px;

color: aliceblue;

width: 70px;

height: 70px;

border-radius: 50%;

border: 20px solid snow

}

#div04{

text-align: center;

font-size: 20px;

font-family: '楷体';

line-height: 70px;

color: aliceblue;

width: 70px;

height: 70px;

border-radius: 50%;

border: 20px solid sandybrown

}

#div05{

text-align: center;

font-size: 20px;

font-family: '楷体';

line-height: 70px;

color: aliceblue;

width: 70px;

height: 70px;

border-radius: 50%;

border: 20px solid salmon

}

#div06{

text-align: center;

font-size: 20px;

font-family: '楷体';

line-height: 70px;

color: aliceblue;

width: 70px;

height: 70px;

border-radius: 50%;

border: 20px solid red

}

#body01{

padding: 5px;

margin: auto;

}

#table01{

margin: auto;

padding: 5px;

}

#h2{

text-align: center;

font-family: '楷体';

}

#button01{

font-family: '楷体';

}

p{

color: aliceblue;

text-align: center;

}

#div012{

background: black;

}

#body02{

margin: auto;

}

</style>

<body>

<h2 id="h2">运维监控</h2>

<table id="table01">

<tbody>

<tr>

<td><button id="butto01" onclick="button01()" style="font-family: 楷体;font-size: 15px;">cpu监控</button></td>

<td><button id="butto01" onclick="button02()" style="font-family: 楷体;font-size: 15px;">memory监控</button></td>

<td><button id="butto01" style="font-family: 楷体;font-size: 15px;">按钮</button></td>

<td><button id="butto01" style="font-family: 楷体;font-size: 15px;">按钮</button></td>

<td><button id="butto01" style="font-family: 楷体;font-size: 15px;">按钮</button></td>

<td><button id="butto01" style="font-family: 楷体;font-size: 15px;">按钮</button></td>

</tr>

</tbody>

</table>

<div id="div010">

<table id="body01">

<body >

<tr>

<td><div id="div01">0</div></td>

<td><div id="div02">0</div></td>

<td><div id="div03">0</div></td>

<!-- <td><div id="div04">4</div></td>

<td><div id="div05">5</div></td>

<td><div id="div06">6</div></td> -->

</tr>

<tr>

<td><p id="p1">监控说明</p ></td>

<td><p id="p2">监控说明</p ></td>

<td><p id="p3">监控说明</p ></td>

<!-- <td><p>4</p ></td>

<td><p>5</p ></td>

<td><p>6</p ></td> -->

</tr>

</body>

</table>

</div>

<div id="div012">

<table id="body02">

<body >

<tr>

<td><div id="div04">0</div></td>

<td><div id="div05">0</div></td>

<td><div id="div06">0</div></td>

</tr>

<tr>

<td><p id="p4">监控说明</p ></td>

<td><p id="p5">监控说明</p ></td>

<td><p id="p6">监控说明</p ></td>

</tr>

</body>

</table>

</div>

</body>

<script>

//数据

var num = [5,7,9,10,13,15,16,18,19,20];

var num01 = ['20°C','30°C','35°C','40°C','50°C','57°C','60°C','66°C','70°C','80°C'];

var num02 = ['10%','20%','37%','46%','52%','59%','62%','68%','75%','82%']

var num03 = [2,3,4,10,14,16,18,21,22,23];

var num04 = [1,2,4,5,6,9,10,11,14,16];

var num05 = ['90%','80%','63%','54%','48%','41%','38%','32%','25%','18%']

var num06 = [10,9,8,7,6,5,4,3,2,1]

var num07 = ['10°C','20°C','30°C','40°C','43°C','46°C','52°C','59°C','65°C','72°C']

var num08 = ['72%','10%','59%','52%','46%','43%','40%','30%','20%','13%']

var num09 = [1,2,3,4,5,6,7,8,9,10]

var num10 = [11,12,13,14,15,16,17,18,19,20]

var num11 = ['28%','90%','41%','48%','54%','57%','60%','70%','80%','87%']

//构造函数

function Button01(j,k,g,a,b,c){

this.j = j

this.k = k

this.g = g

this.a = a

this.b = b

this.c = c

this.num02 = Math.floor(Math.random()*10);

this.num03 = this.j[this.num02]

this.num04 = this.a[this.num02]

this.num05 = this.b[this.num02]

}

//调用构造函数并赋值,用于cpu的变化操作

function f1(){

var but01 = new Button01(num,num01,num02,num03,num04,num05)

document.getElementById("div01").style.border= but01.num03+'px'+' '+'solid steelblue';

document.getElementById("div01").innerText = but01.k[but01.num02];

document.getElementById("div02").style.border = but01.num04+'px'+' '+'solid silver';

document.getElementById("div02").innerText = but01.g[but01.num02]

document.getElementById("div03").style.border = but01.num05+'px'+' '+'solid snow';

document.getElementById("div03").innerText = but01.c[but01.num02];

}

//触发cpu监控的

function button01(){

document.getElementById('p1').innerText = 'CPU温度';

document.getElementById('p2').innerText = 'CPU使用';

document.getElementById('p3').innerText = 'cpu空闲';

setInterval(f1,2000);

}

//调用构造函数并赋值,用于Mem内存的变化操作

function f2(){

var but02 = new Button01(num06,num07,num08,num09,num10,num11)

document.getElementById("div04").style.border= but02.num03+'px'+' '+'solid sandybrown';

document.getElementById("div04").innerText = but02.k[but02.num02];

document.getElementById("div05").style.border = but02.num04+'px'+' '+'solid salmon';

document.getElementById("div05").innerText = but02.g[but02.num02]

document.getElementById("div06").style.border = but02.num05+'px'+' '+'solid red';

document.getElementById("div06").innerText = but02.c[but02.num02];

}

//触发内存监控的

function button02(){

document.getElementById('p4').innerText = 'Mem温度';

document.getElementById('p5').innerText = 'Mem使用';

document.getElementById('p6').innerText = 'Mem空闲';

setInterval(f2,2000);

}

</script>

</html>

标签: #数据结构及算法js