鼠标移过随机变换颜色

Original 2019-06-10 16:33:26 160
abstract:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JavaScript小案例</title> <style type="text/css"> div{width:&n
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>JavaScript小案例</title>
	<style type="text/css">
		div{width: 100px;height: 100px;background-color: #ccc;margin-top: 10px;border-radius: 50px;display: inline-block;}

	</style>
</head>
<body>
<div onmouseover="myOnclick(this)";></div>
<div onmouseover="myOnclick(this)";></div>
<div onmouseover="myOnclick(this)";></div>
<div onmouseover="myOnclick(this)";></div>
<div onmouseover="myOnclick(this)";></div>
<div onmouseover="myOnclick(this)";></div>
<div onmouseover="myOnclick(this)";></div>
<div onmouseover="myOnclick(this)";></div>
<div onmouseover="myOnclick(this)";></div>
<div onmouseover="myOnclick(this)";></div>
<div onmouseover="myOnclick(this)";></div>
<script type="text/javascript">
function myOnclick(x) {
   var clr = getRandomColor( )
    x.style.backgroundColor="#"+clr;
};

function getRandomColor( ) {
    var rand = Math.floor(Math.random( ) * 0xFFFFFF).toString(16);
    if(rand.length == 6){
        return rand;
    }else{
        return getRandomColor();
    }
};

</script>
</body>
</html>


Correcting teacher:查无此人Correction time:2019-06-11 09:12:09
Teacher's summary:完成的不错。js的+号拼接,最好在+号前后增加空格。继续加油。

Release Notes

Popular Entries