📘
Luckydesigner
  • Knowledge Code Guide
  • HTML CODE
    • Dictionary
  • CSS CODE
    • Dictionary
  • Javascript Code
    • Dictionary
    • Examples
    • Reference
  • Regular Expressions
    • Reference
  • Wechat Mini Program Develop Notes
    • 开篇
    • 流程
    • 构成
      • 框架
    • 配置
      • index.wxml+index.js
      • Button
      • UserInfo
      • TabBar
      • Clipboard
    • Api
      • 背景
      • 交互
      • 导航栏
    • 标签
Powered by GitBook
On this page

Was this helpful?

  1. Javascript Code

Examples

Change Random Colors

<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>canvas</title>
</head>

<body>
	<div id="demo">I love you!</div>
	<button onclick="changeVal();">click me</button>
<script>
		function changeVal(){
			var obj=document.getElementById("demo");
			var r = Math.floor(Math.random()*255);
			var g = Math.floor(Math.random()*255);
			var b = Math.floor(Math.random()*255);
            var color = "#"+r.toString(16)+g.toString(16)+b.toString(16);
			if(obj.innerHTML=="I love you!"){
					obj.innerHTML="I hate you!";
					obj.style.color = color;
				}else if(obj.innerHTML=="I hate you!"){
					obj.innerHTML="I love you!";
					obj.style.color = color;
					}
		}
</script>
</body>
</html>
PreviousDictionaryNextReference

Last updated 4 years ago

Was this helpful?