不訪問值我學習JavaScript和XHTML首次在此刻,我現在有我一直沒能解決問題。我認爲這是一個相當簡單的解決方法,我只是不需要知識就能做到。這裏是javascript以及我如何試圖從xhtml調用它。Javascript語言,形式
這是所謂的greet.js JavaScript文件。
function tOD() {
timeOfDay = new Date
if (timeOfDay.getHours() < 5) {
alert("Either go to bed, or go back to bed " + document.form[0].inputname.value);
}
else if (timeOfDay.getHours() < 11) {
alert("Rise and shine " + document.form[0].inputname.value);
}
else if (timeOfDay.getHours() < 17) {
alert("Good afternoon " document.form[0].inputname.value);
}
else {
alert("And after a hard day at work you can relax at last, " + document.form[0].inputname.value);
}
}
這裏是我試圖在我的xhtml中實現它的地方。
<script type="text/javascript" src="greet.js"></script>
<FORM NAME = input>
Please enter your name:
<input type= "text" name = "inputName"/>
<input Type= Button NAME= "greeting" VALUE="ok" onClick="greet()"/>
</FORM>
中,如果我拿走document.form JavaScript的作品[0] .inputname.value它會用一天的正確時間,當我按下按鈕發出警報。所以它必須是document.form [0] .inputname.value,這一定是錯誤的,我只是不確定如何解決它。我一直在使用的元素[0],而不是形式,[0],並輸入和元素[輸入]也試過,所以我不知道它可能是什麼...
感謝所有幫助表示讚賞。
啊,非常感謝,這是非常有幫助的,我看到我的,現在出了問題。 – DanMc 2012-03-18 16:53:11