Я новичок в веб-программировании и надеялся создать систему, которая будет случайным образом выбирать, кто из учеников принудительно пересматривает рюкзак. Недавно ученик угрожал расстрелять школу, с того события прошло 1 месяц, так что школа вместо проведя поиск по всем учащимся, решил сделать его полностью случайным, поэтому я решил создать веб-страницу, которая именно это и делает.
Однако пожилые люди будут использовать ее, и хотя я разобрал часть кода, Я хотел сделать фон веб-сайта красным, если требуется пересмотр, и зеленым, если результат алгоритма рандомизации равен проходу.
Вот мой код:
HTML:
<html lang="en">
<head>
<meta charset="UTF-8">
<title>SELEC</title>
<link rel="stylesheet" href="quote.css">
<link href='https://fonts.googleapis.com/css?family=Roboto:400,700' rel='stylesheet' type='text/css'>
<script src="jquery-1.11.2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<h2>Random Student Selection System</h2>
<div id="quoteContainer">
<p></p>
<p id="quoteGenius"></p>
</div><!--end quoteContainer-->
<div id="buttonContainer">
<a href="#" id="quoteButton">GEN</a>
</div><!--end buttonContainer-->
</div><!--end container-->
</body>
</html>
JS:
$(document).ready(function(){
var quoteSource=[
{
quote: "PASS",
name:"PASS"
},
{
quote:"REVISION",
name:"REVISION"
},
];
$('#quoteButton').click(function(evt){
//define the containers of the info we target
var quote = $('#quoteContainer p').text();
var quoteGenius = $('#quoteGenius').text();
//prevent browser's default action
evt.preventDefault();
//getting a new random number to attach to a quote and setting a limit
var sourceLength = quoteSource.length;
var randomNumber= Math.floor(Math.random()*sourceLength);
//set a new quote
for(i=0;i<=sourceLength;i+=1){
var newQuoteText = quoteSource[randomNumber].quote;
var newQuoteGenius = quoteSource[randomNumber].name;
//console.log(newQuoteText,newQuoteGenius);
var timeAnimation = 100;
var quoteContainer = $('#quoteContainer');
//fade out animation with callback
quoteContainer.fadeOut(timeAnimation, function(){
quoteContainer.html('');
quoteContainer.append('<p>'+newQuoteText+'</p>'+'<p id="quoteGenius">'+'- '+newQuoteGenius+'</p>');
//fadein animation.
quoteContainer.fadeIn(timeAnimation);
});
break;
};//end for loop
});//end quoteButton function
});//end document ready
и CSS
body{
font-family: 'Roboto', sans-serif;
color: #000;
}
#container{
width:800px;
margin:50px auto;
padding: 20px;
width:50%;
}
#container h2{
text-align:center;
color:#045;
}
#quoteContainer{
width:75%;
background: #fff;
padding:10px;
margin:30px auto;
text-align: center;
height:70px;
}
#buttonContainer{
width: 100%;
text-align: center;
}
#quoteButton{
width:200px;
margin-top: 10px;
border:2px solid #E8450C;
color:#045;
font-family: inherit;
font-weight: bold;
padding:5px;
text-decoration: none;
text-align: center;
}
#quoteButton:hover{
cursor:pointer;
background:#E82B13;
color: #fff;
}
#quoteButton:active{
cursor: pointer;
}
#quoteButton{
display: inline-block;
}
#quoteGenius{
font-style: italic;
font-weight: 600;
text-align: center;
}
/*MEDIA QUERIES*/
@media screen and(max-width:760px){
#quoteButton,#addNew{
display: block;
}
}
Я только начал изучать это на прошлой неделе. Заранее спасибо. Привет.