【文章內(nèi)容簡(jiǎn)介】
e 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 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。s Day. var now = new Datevar then = new Date(January 1, 2002) The variable now in the above example actually holds the number of milliseconds that have passed since the puter started counting until now. The variable then in the above example actually holds the number of milliseconds that will have passed between the time the puter started counting and January 1, 2002. By subracting the two amounts and storing the answer in a new variable you will know the number of milliseconds between now and your target date. With a little division, this number can be converted to the number of days between now and your target date. In order to display the result as an integer, you will need to use the function as in the following example which uses the variable numdays to hold the number of days to be displayed. Ceil is short for ceiling which implies that the number will be rounded up to the nearest whole number. (Only + (numdays) + days until New Year39。s!) INTERACTIVE FORMSForms can be used for a lot more than just submitting information through . Forms can be made to perform all sorts of actions when buttons are clicked.中文翻譯出處:使用JavaScript設(shè)計(jì)網(wǎng)頁(yè)THE BASICS基礎(chǔ)JAVASCRIPT uses a subset of the programming language JAVA to provide a high level of interactivity on a web page. JavaScript使用編程語(yǔ)言Java的一個(gè)子集在網(wǎng)頁(yè)上提供高層次的交互。 JavaScripts are stored within an HTML document and are interpreted by the web browser. JAVAScripts以HTML文件格式存儲(chǔ),并是由Web瀏覽器解釋。JavaScripts may be located within the HTML code at the point in the page where they are to appear on the screen or they may be written using functions. JavaScript可能位于HTML代碼中他們?cè)谄聊恢谐霈F(xiàn)的位置上,也可能用函數(shù)寫成。Functions are small subprograms that are stored between the head tags of an HTML document and are called on to be executed when a particular event ,存儲(chǔ)于HTML文件的頭標(biāo)簽之間,當(dāng)一個(gè)特定的事件發(fā)生時(shí)將被調(diào)用執(zhí)行。Whether the script is stored between the head tags or within the body of the HTML document, it must be enclosed in script ,它都必須包含在腳本標(biāo)記。Also, a set of HTML ment tags are typically used inside the script tags so that older browsers that do not support JavaScript will ignore the script and continue to process the page without ,HTML注釋標(biāo)記通常用于腳本標(biāo)記內(nèi),這樣,不支持JavaScript的舊版瀏覽器會(huì)忽略腳本并繼續(xù)處理頁(yè)面,而不顯示錯(cuò)誤。Following is an example of the script and ment tags:以下是一個(gè)腳本和注釋標(biāo)簽的例子: script language=javascriptscript language=javascript!這里包含的JavaScript代碼///script !Include JavaScript Code Here///scriptBe aware that JavaScript is case sensitive...the difference between a working script and an error message can be one capital ,JavaScript是區(qū)分大小寫的...一個(gè)可運(yùn)行腳本同錯(cuò)誤消息的區(qū)別常常就在于一個(gè)大寫字母。 ALERT BOXES 警告框To pop up an alert box include the following line of code inside of script tags in the body of your HTML document. 為了彈出一個(gè)警告框,可將下面一行代碼包含到你的HTML文件的BODY中的腳本標(biāo)簽里。Please note that the processing of the page will stop until the viewer responds to the alert ,直到用戶響應(yīng)警告框。 alert (Place the text to be displayed in the alert box between these quotes.)alert (將要顯示在警告框中的文本寫在引號(hào)之間)Other types of premade dialog boxes are available such as the prompt and confirm ,還有其他類型的預(yù)制對(duì)話框可用,如提示框和確認(rèn)框。In order to take full advantage of the features of these dialog boxes you must write more JavaScript code which can use the values that are returned by the dialog ,則必須編寫更多的JavaScript代碼,來(lái)使用這些對(duì)話返回的參數(shù)值。The following statements will pop up a dialog box that requires a yes or no answer (OK or Cancel).下面的語(yǔ)句會(huì)彈出一個(gè)對(duì)話框,需要回答是或否(確定或取消)。If the answer is OK then the variable named answer has a value of true and if the answer is Cancel then the variable named answer has a value of ,則以不同名字命名的變量會(huì)被賦予真值;如果答案是取消,則以不同名字命名的變量會(huì)被賦予假值。You can then use an if statement in the JavaScript code to respond ,您可以使用JavaScript代碼語(yǔ)句作出適當(dāng)響應(yīng)。var answer = confirm (Are you sure you want to quit?)if (answer==true){()}var answer = confirm (Are you sure you want to quit?)if (answer==true){()}The following code will pop up a dialog box that asks the user to enter