【正文】
o access various parts of the date and time including day of the week, month, day of the month, year, hours (in military time), minutes, and seconds. Assuming that now is the variable declared of type Date the following table describes how to access the parts of the date and time. Each of the function calls may be used in a statement to display the result. Table13 various parts of the Date type variable Function Call Description ( ) Returns a number between 0 and 6 for the day of the week (Sunday is 0, Monday is 1,...) ( ) Returns a number between 0 and 11 for the month (January is 0, February is 1,...) ( ) Returns the number of the day in the month (1 31) ( ) Returns the four digit year ( ) Returns the number of hours on the clock (0 23) ( ) Returns the number of minutes on the clock (0 59) ( ) Returns the number of seconds on the clock (0 59) One way to convert the numbers for the month and day of week in to words is to use if statements. Using a lot of if statements is not the most efficient way to display the words, but it is the method that requires the least amount of programming knowledge. Examine the following example. Notice the condition that follows the word if is in parentheses and that a double equal sign is used for the parison. A single equal sign will actually make the condition true no matter what so January would always be displayed. if (( ) == 0) (January) The following function would display a working clock if your page contained a form 大連交通大學(xué) 2021 屆本科生畢業(yè)設(shè)計(jì)(論文)外文翻譯 7 called myform which contained a text box named mybox and the function was called using the onload event handler in the body tag. More code would need to be added to assure that the minutes and seconds always used two digits. function myclock( ) { var now = new Date = ( )+:+( )+:+( ) (myclock( ),1000) } To display a countdown to a future date, you will need two variables of type new Date. One of them will need to be set to the date that you are targeting with your countdown. The declarations would look as follows if you were going to count down to New Year39。 JavaScript 可能位于 HTML 代碼中他們?cè)谄聊恢谐霈F(xiàn)的位置上,也可能用函數(shù) 寫(xiě)成。 以下是一個(gè)腳本和注釋標(biāo)簽的例子: script language=javascript ! 這里包含的 JavaScript 代碼 // /script 要知道, JavaScript 是區(qū)分大小寫(xiě)的 ...一個(gè)可運(yùn)行腳本同錯(cuò)誤消息的區(qū)別常常就在于一個(gè)大寫(xiě) 字母。 為了充分利用這些對(duì)話(huà)框的功能,則必須編寫(xiě)更多的 JavaScript 代碼,來(lái)使用這些對(duì)話(huà)返回的參數(shù)值。 var answer = confirm (Are you sure you want to quit?) if (answer==true) { () } 大連交通大學(xué) 2021 屆本科生畢業(yè)設(shè)計(jì)(論文)外文翻譯 9 下面的代碼將彈出一個(gè)對(duì)話(huà)框,要求用戶(hù)輸入某些信息。 窗口是指在瀏覽器窗口,而文檔是指顯示的頁(yè)面。例如在下面的例子中打開(kāi)方法分為三部分:在新打開(kāi)窗口中要顯示的文件名稱(chēng)或網(wǎng)站的 URL,可能用到的支出瀏覽器窗口的名字(所需實(shí)際代碼比我們這里展示的要多),以及新窗口的屬性。 該函數(shù)的基本結(jié)構(gòu)如下: function NameOfFunction( ) { JavaScript 代碼 } 事件處理程序 下面的例子展示了 onclick事件處理程序的使用,以及使用樣式來(lái)控制按鈕的外觀。 fontfamily : arial。 borderwidth : 。 function myfunction( ) { = } 下面是 JavaScript 中存在的一些事件處理程序: 表 12 JavaScript 中存在的一些事件處理程序 onfocus onblur onselect onchange onsubmit onclick onmouseover onmouseout onload onunload onabort onerror onreset onkeypress onkeyup onmousedown onmousemove onmouseup onmove onresize 彈出菜單 彈出菜單可以使用選擇標(biāo)記快速建立,因?yàn)樗怯糜诮⑾吕斜淼摹? 默認(rèn)情況下列表中只顯示有一項(xiàng)(用一條選擇語(yǔ)句),只 有用戶(hù)點(diǎn)擊下箭頭是才將列表其余部分展開(kāi)。產(chǎn)生鼠標(biāo)懸停最快捷的方法就是利用 onmouseover 和 onmouseout 事件處理程序。39。 有了這個(gè) JavaScript 也是很容易把滾動(dòng)文字放在狀態(tài)欄上,而不是在它自己的文件中利用 作為消息的目的地。 顯示最后更新的日期和時(shí)間的一個(gè)好的做法,因?yàn)轭l繁更新是網(wǎng)站質(zhì)量的標(biāo)志。 假設(shè), 現(xiàn)在已經(jīng)聲明了一個(gè) Date 類(lèi)型的變量,下表描述了 如何大連交通大學(xué) 2021 屆本科生畢業(yè)設(shè)計(jì)(論文)外文翻譯 13 訪(fǎng)問(wèn)時(shí)間和日期的不同部分。 仔細(xì)觀察下面的例子。 function myclock( ) { var now = new Date = ( )+:+( )+:+( ) (myclock( ),1000) } 要顯示到未來(lái)某一天的倒計(jì),則需要兩個(gè) Date 類(lèi)型的變量 。 上面例子中的變量 then實(shí)際上保存的是從計(jì)算機(jī)開(kāi)始計(jì)數(shù)到在 2021年 1月 1日要經(jīng)過(guò)的毫秒數(shù)。 Ceil 是 ceiling的縮寫(xiě),意味著該數(shù)將四舍五入到最近的整數(shù)。