클래스 용 간단한 스크립트를 만들려고합니다. 나는 onclick 이벤트를 수행하고 배열을 따로 처리하는 방법을 알았지 만 함께 작동시키는 방법을 모르겠습니다. 나는 아직도 행운이 새로 고침에 변화하고 싶지만 버튼을 클릭하는 옵션이있다.배열로 onclick 작업하기
온 클릭 :
<button onclick="myFunction()">Get your fortune!</button>
<p id="fortune"></p>
<script>
function myFunction() {
document.getElementById("fortune").innerHTML = ???? ;
}
</script>
배열이 같은
<script>
var fortune = new Array(10);
fortune[0]="May life throw you a pleasant curve.";
fortune[1]="Procrastination is the thief of time.";
fortune[2]="Your road to glory will be rocky, but fulfilling.";
fortune[3]="Patience is your alley at the moment. Don’t worry!";
fortune[4]="All things are difficult before they are easy.";
fortune[5]="If you want the rainbow, you have to tolerate the rain.";
fortune[6]="Determination is what you need now.";
fortune[7]="Do not let ambitions overshadow small success.";
fortune[8]="First think of what you want to do; then do what you have to do.";
fortune[9]="Hard words break no bones, fine words butter no parsnips.";
c=Math.round(Math.random()*9);
document.write(fortune[c]);
</script>