所以这是我的目标,我需要能够确定用户点击的 div 的背景颜色是什么。每个 div 都有一个确定其背景的函数。我将如何使用 javascript 来跟踪函数,或者更容易将该数据发送到 url,以便我可以将其与预定代码进行比较?
<?php "session_start" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<?php
$cols = array(
"#000000",
"#FFFFFF",
"#0000FF",
"#008000",
"#800080",
"#FF0000",
"#FFFF00",
"#DD7500",
"#4FD5D6",
"#CD6090",
);
function getRandomColor1() {
global $cols;
$num_cols = count($cols);
$rand = array_rand($cols);
$rand_col = $cols[$rand];
unset($cols[$rand]);
return $rand_col;
}
function getRandomColor2() {
global $cols;
$num_cols = count($cols);
$rand = array_rand($cols);
$rand_col = $cols[$rand];
unset($cols[$rand]);
return $rand_col;
}
function getRandomColor3() {
global $cols;
$num_cols = count($cols);
$rand = array_rand($cols);
$rand_col = $cols[$rand];
unset($cols[$rand]);
return $rand_col;
}
function getRandomColor4() {
global $cols;
$num_cols = count($cols);
$rand = array_rand($cols);
$rand_col = $cols[$rand];
unset($cols[$rand]);
return $rand_col;
}
function getRandomColor5() {
global $cols;
$num_cols = count($cols);
$rand = array_rand($cols);
$rand_col = $cols[$rand];
unset($cols[$rand]);
return $rand_col;
}
function getRandomColor6() {
global $cols;
$num_cols = count($cols);
$rand = array_rand($cols);
$rand_col = $cols[$rand];
unset($cols[$rand]);
return $rand_col;
}
function getRandomColor7() {
global $cols;
$num_cols = count($cols);
$rand = array_rand($cols);
$rand_col = $cols[$rand];
unset($cols[$rand]);
return $rand_col;
}
function getRandomColor8() {
global $cols;
$num_cols = count($cols);
$rand = array_rand($cols);
$rand_col = $cols[$rand];
unset($cols[$rand]);
return $rand_col;
}
function getRandomColor9() {
global $cols;
$num_cols = count($cols);
$rand = array_rand($cols);
$rand_col = $cols[$rand];
unset($cols[$rand]);
return $rand_col;
}
function getRandomColor10() {
global $cols;
$num_cols = count($cols);
$rand = array_rand($cols);
$rand_col = $cols[$rand];
unset($cols[$rand]);
return $rand_col;
}
?>
<style media="screen" type="text/css">
#full {
height: 300px;
width: 750px;
border: 3px solid #999;
margin: 0 auto;
}
#boxone1 {
height: 150px;
width: 150px;
background: <?php echo getRandomColor1(); ?>; ;
float: left;
}
#boxone2 {
height: 150px;
width: 150px;
background: <?php echo getRandomColor2(); ?>;
float: left;
}
#boxone3 {
height: 150px;
width: 150px;
background: <?php echo getRandomColor3(); ?>;
float: left;
}
#boxone4 {
height: 150px;
width: 150px;
background: <?php echo getRandomColor4(); ?>;
float: left;
}
#boxone5 {
height: 150px;
width: 150px;
background: <?php echo getRandomColor5(); ?>;
float: left;
}
#boxtwo1 {
height: 150px;
width: 150px;
background: <?php echo getRandomColor6(); ?>;
float: left;
}
#boxtwo2 {
height: 150px;
width: 150px;
background: <?php echo getRandomColor7(); ?>;
float: left;
}
#boxtwo3 {
height: 150px;
width: 150px;
background: <?php echo getRandomColor8(); ?>;
float: left;
}
#boxtwo4 {
height: 150px;
width: 150px;
background: <?php echo getRandomColor9(); ?>;
float: left;
}
#boxtwo5 {
height: 150px;
width: 150px;
background: <?php echo getRandomColor10(); ?>;
float: left;
}
</style>
<body>
<div id="full">
<div id="boxone1" onClick="window.location='?name='+this.id" style=""></div>
<div id="boxone2" onClick="window.location='?name='+this.id" style=""></div>
<div id="boxone3" onClick="window.location='?name='+this.id" style=""></div>
<div id="boxone4" onClick="window.location='?name='+this.id" style=""></div>
<div id="boxone5" onClick="window.location='?name='+this.id" style=""></div>
<div id="boxtwo1" onClick="window.location='?name='+this.id" style=""></div>
<div id="boxtwo2" onClick="window.location='?name='+this.id" style=""></div>
<div id="boxtwo3" onClick="window.location='?name='+this.id" style=""></div>
<div id="boxtwo4" onClick="window.location='?name='+this.id" style=""></div>
<div id="boxtwo5" onClick="window.location='?name='+this.id" style=""></div>
</div>
</div>
</body>
</html>
或多或少,我想知道如何收集选择颜色的顺序并将它们与预定模式进行比较。通过js还是通过在url中发布会更好吗?无论哪种方式,有人可以证明它是如何完成的吗?