2016-04-05 16 views
0

Ben alıntı ve rasgele bir diziden bir ad alıp bunları HTML sayfamda görüntülemek zorunda olduğum bir ödev üzerinde çalışıyorum. Bazı dolgu metni altında. Herhangi bir sebepten dolayı, betik çalışıyor ve farklı bir kimlik (basit bir yerel tarih, bir zaman göstergesi) gösteriliyor, ancak teklif rastgele değil. Herhangi bir yardım büyük takdir edilecektir.HTML'den URL'de çağrıldığında "id" yazdırılmıyor

HTML

</head> 
    <body> 
    <h1>CIS - 16W</h1> 
<nav id="nav"> 
    <ul> 
     <li><a href="../p1/assign1/">Home</a></li> 
     <li><a href="../p1/assign2/">Assignment 2</a></li> 
     <li><a href="../p1/assign3/">Assignment 3</a></li> 
     <li><a href="../p1/assign4/">Assignment 4</a></li> 
     <li><a href="../p1/assign5/">Assignment 5</a></li> 
     <li><a href="../p1/assign6/">Assignment 6</a></li> 
     <li><a href="../p1/assign7/">Assignment 7</a></li> 
     <li><a href="../p1/fp/">Final Project</a></li> 
    </ul> 
</nav> 
</body> 
    <meta charset="utf-8"> 
     <meta name=“description” content=“description”> 
     <meta name=“author” content=“your”> 
     <link rel="stylesheet" href="../css/styles.css"> 
     <script src="../functions.js"></script> 
<main> 
    <p>My name is _____ and I am a junior here at the _____.<br>I'm very excited to get started and hone in my skills in the multimedia environment! 
    </p> 
    <p>I am taking this course to help not only fill the math requirment for a Bacholer of Science, but also to aid my Multimedia minor and Advertising major!</p> 
    <span id="quote"></span> 
    <span id="name"></span> 

JavaScript yerde

window.onload = function() { 
setInterval(timeAndDate, 1000); 
} 


var quotes = ["\"How many cares one loses when one decides not to be something but to be someone.\"", 
"\"If you want to test a man's character give him power.\"", 
"\"I just hope that one day, perferably when we're both blind drunk, we can talk about it\"", 
"\"Why do you look so sad?'<br>'Because you speak to me in words and I look at you with feelings.\"", 
"\"Courage is what it takes to stand up and speak. Courage is also what it takes to sit down and listen.\""]; 
var names = ["-Coco Chanel", "-Abrham Lincoln", "-J. D. Salinger", "-Leo Tolstoy", "-Wiston Churchill"]; 

var arrIndex = Math.floor(Math.random() * (quotes.length)); 

function quoteGen() { 
    var quoteAll = document.getElementById("quote"); 
    var namesAll = document.getElementById("name"); 
    quoteAll.innerHTML = quotes[arrIndex]; 
    namesAll.innerHTML = names[arrIndex]; 
    if (arrIndex > quotes.length-1) { 
     arrIndex = 0; 
    } 
} 


function timeAndDate() { 
    var date = new Date(); 
    var n = date.toDateString(); 
    var time = date.toLocaleTimeString(); 
    document.getElementById('localDate').innerHTML = n + ' ' + time; 
} 
+0

sayfa –

cevap

0

,

    Sen, zamanlayıcı ihtiyacı quoteGen diyoruz ancak tırnak güncelliyor quoteGen demiyorsun
  • zamanlamanın güncellendiğini neden değil tırnak olduğunu timeAndDate aradığınız her çağırma yeni bir rastgele değer elde edecek şekilde
  • Sen quoteGen içinde rasgele indeksi oluşturmak gerekir

window.onload = function() { 
 
    setInterval(quoteGen, 1000); 
 
} 
 

 

 
var quotes = ["\"How many cares one loses when one decides not to be something but to be someone.\"", 
 
    "\"If you want to test a man's character give him power.\"", 
 
    "\"I just hope that one day, perferably when we're both blind drunk, we can talk about it\"", 
 
    "\"Why do you look so sad?'<br>'Because you speak to me in words and I look at you with feelings.\"", 
 
    "\"Courage is what it takes to stand up and speak. Courage is also what it takes to sit down and listen.\"" 
 
]; 
 
var names = ["-Coco Chanel", "-Abrham Lincoln", "-J. D. Salinger", "-Leo Tolstoy", "-Wiston Churchill"]; 
 

 
var idx; 
 

 
function quoteGen() { 
 
    //the looping is used to make sure that every call to quoteGen will update a new quote 
 
    do { 
 
    var arrIndex = Math.floor(Math.random() * (quotes.length)); 
 
    } while (idx == arrIndex); 
 
    idx = arrIndex; 
 
    var quoteAll = document.getElementById("quote"); 
 
    var namesAll = document.getElementById("name"); 
 
    quoteAll.innerHTML = quotes[arrIndex]; 
 
    namesAll.innerHTML = names[arrIndex]; 
 
}
<p>My name is _____ and I am a junior here at the _____. 
 
    <br>I'm very excited to get started and hone in my skills in the multimedia environment! 
 
</p> 
 
<p>I am taking this course to help not only fill the math requirment for a Bacholer of Science, but also to aid my Multimedia minor and Advertising major!</p> 
 
<span id="quote"></span> 
 
<span id="name"></span>

+0

https://jsfiddle.net/arunpjohny/yu1q70q7/ hiçbir 'localDate' yoktur –

0

Sen quoteGen çağırarak değil(). Burada 2 sorun var

İlgili konular