【正文】
rolling text instead. With this JavaScript it is also quite easy to place the scrolling text on the status bar instead of in the document itself by using as the destination for the message. The following function will generate a scrolling message in a text box named mymessagebox which is part of a form named myform. The event handler onload must also be used in the body tag to call the function when the page loads. var message = This is a test... JavaScripts are stored within an HTML document and are interpreted by the web browser. JAVAScripts以HTML文件格式存儲(chǔ),并是由Web瀏覽器解釋。 alert (Place the text to be displayed in the alert box between these quotes.)alert (將要顯示在警告框中的文本寫(xiě)在引號(hào)之間)Other types of premade dialog boxes are available such as the prompt and confirm ,還有其他類(lèi)型的預(yù)制對(duì)話(huà)框可用,如提示框和確認(rèn)框。 var response = prompt (What is your name? ,) (font size=7 color=red face=arialHello + response + !) var response = prompt (What is your name? ,) (font size=7 color=red face=arialHello + response + !)Notice that in the last two examples the window and document objects were ,最后兩個(gè)例子中使用了窗口和文檔對(duì)象。例如在下面的例子中打開(kāi)方法分為三部分:在新打開(kāi)窗口中要顯示的文件名稱(chēng)或網(wǎng)站的URL,可能用到的支出瀏覽器窗口的名字(所需實(shí)際代碼比我們這里展示的要多),以及新窗口的屬性。 fontfamily : arial。 bordercolor : red}/style/headbodyform name=myforminput type=button name=mybutton id=bigbutton value=CLICK ME!在鉆則標(biāo)簽中設(shè)置選項(xiàng)的值,指示要顯示新的一頁(yè)的URL。作為鼠標(biāo)懸停的結(jié)果,任何應(yīng)用于特定對(duì)象的樣式屬性都可以被改變。The following function will generate a scrolling message in a text box named mymessagebox which is part of a form named 。 表13 Date類(lèi)型變量中的不同部分及其描述函數(shù)調(diào)用描述( ) 返回0到6之間的數(shù)來(lái)表明星期幾(星期日是0,星期一是1,以此類(lèi)推) ( ) 返回0到11之間的數(shù)字來(lái)表明月份 (一月是0,二月是1,以此類(lèi)推) ( ) 返回月中的一天 (1 31) ( ) 返回四位年份( ) 返回小時(shí)(0 23) ( ) 返回分鐘(0 59) ( ) 返回秒 (0 59) One way to convert the numbers for the month and day of week in to words is to use if if 語(yǔ)句。如果是到新年的倒計(jì)時(shí),聲明如下。s!) (Only + (numdays) + days until NewYear39。Ceil是ceiling的縮寫(xiě),意味著該數(shù)將四舍五入到最近的整數(shù)。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。 function myclock( ){Assuming that now is the variable declared of type Date the following table describes how to access the parts of the date and , 現(xiàn)在已經(jīng)聲明了一個(gè)Date類(lèi)型的變量,下表描述了如何訪(fǎng)問(wèn)時(shí)間和日期的不同部分。(position, ) + SCROLLING TEXT滾動(dòng)文字 由于只有IE瀏覽器支持字幕標(biāo)簽,所以應(yīng)該盡量避免使用它,而利用一個(gè)JavaScript來(lái)產(chǎn)生滾動(dòng)文字。 MOUSEOVERS 鼠標(biāo)懸停A mouseover refers to the effect that occurs when the properties of an object are changed if the mouse is positioned over the top of the object and then again if the mouse is removed from the object. 鼠標(biāo)懸停,是指當(dāng)鼠標(biāo)位于一個(gè)對(duì)象上,然后又離開(kāi)對(duì)象區(qū)域時(shí),對(duì)對(duì)象屬性產(chǎn)生的影響。通常只寫(xiě)一個(gè)函數(shù),除非要求一個(gè)以上事情發(fā)生。 height : 50px。Copy and paste this entire set of code in to a new document and test it ,并測(cè)試它。If the user clicks OK the information they entered is stored in the 。 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)簽里。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。 onmouseout=src=39。 color : blue。 borderwidth : 。 var position = 0function mymessage( ){ = var now = new DateJavaScripts 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ù)寫(xiě)成。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 ,則必須編寫(xiě)更多的JavaScript代碼,來(lái)使用這些對(duì)話(huà)返回的參數(shù)值。Window refers to the browser window and document refers to the page being ,而文檔是指顯示的頁(yè)面。請(qǐng)注意,所有屬性將在一對(duì)引號(hào)中列出,用逗號(hào)分割開(kāi)。 color : blue。Set the value of each of the options in the select tag to the url of the new page to be displayed. Use the onchange event handler to set the location of the window to the selected value in the drop down 。The quickest way to generate a mouseover is to use the onmouseover and onmouseout event handlers in a form of inline the style section of the DHTML page of this web site to see an example of mouseovers used with text as an inline style.Performing mouseovers with a graphic is not much different than with text. 在圖形上實(shí)現(xiàn)鼠標(biāo)懸停與文本沒(méi)有太大區(qū)別。當(dāng)頁(yè)面載入是,onlord事件處理程序也必須