Събитието ONCLICK DHTML Event Model - ONCLICK alert( "Първи текст" ); опитайте да кликнете тук! <INPUT TYPE = "button" VALUE = "Разгледайте реакцията на.

Slides:



Advertisements
Similar presentations
JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
Advertisements

Session 11 Dynamic HTML: Event Model and Filters Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
JavaScript (Part 2) CS 183 4/13/2010. JavaScript (Part 2) Will cover: ◦ For.. In ◦ Events ◦ Try.. Catch, Throw ◦ Objects.
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
JavaScript Forms Form Validation Cookies CGI Programs.
20-Jun-15 JavaScript and HTML Simple Event Handling.
Page 1 of 39 Javascript Chapters 13, 14 Vadim Parizher Computer Science Department California State University, Northridge Fall 2003 Slides from text Book.
Lesson 2 Event Handling. Object Event Handlers Most of the objects that make up the Document Object Model respond to asynchronous, user generated events.
JavaScript Client Side scripting. Client-side Scripts Client-side scripts, which run on the user’s workstation can be used to: Validate user inputs entered.
UNIT 6 JAVASCRIPT EVENT HANDLERS &WEB BROWSERS DETECTION.
CP476 Internet Computing JavaScript and HTML1 1.JavaScript Execution Environment The JavaScript Window object represents the window in which the browser.
JS: DOM Form Form Object Form Object –The Form object represents an HTML form. –For each instance of a tag in an HTML document, a Form object is created.
HTML Forms/Events (Instructor Lesson) The Event model HTML Forms Custom Events 1.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
JavaScript - a Brief Introduction Anupriya. What is JavaScript Object based (not object oriented) programming language –very limited object creation –a.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
Chapter 19: Adding JavaScript
Chapter 5 © 2003 by Addison-Wesley, Inc. 1 Chapter 5 JavaScript and HTML Documents.
JavaScript – part II. The if Statement if (condition) { block of code to be executed if the condition is true }
CSS Class 7 Add JavaScript to your page Add event handlers Validate a form Open a new window Hide and show elements Swap images Debug JavaScript.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 13 - Dynamic HTML: Object Model and Collections Outline 13.1 Introduction 13.2 Object Referencing.
1 Dynamic HTML III: Event Model Introduction Event model –Scripts respond to user actions and change page accordingly Moving mouse Scrolling screen.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 16 – Dynamic HTML: Event Model Outline 16.1Introduction 16.2Event ONCLICK 16.3Event ONLOAD.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 14 - Dynamic HTML: Event Model Outline 14.1 Introduction 14.2 Event onclick 14.3 Event onload 14.4.
Pemrograman Teknologi Internet W06: Functions and Events.
DOM Events. JS Events Outline About Events – Introduction – Registering events – Getting information from events Event order/phases – Preventing default.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 14 - Dynamic HTML: Event Model Outline 14.1 Introduction 14.2 Event onclick 14.3 Event onload.
Intro to JavaScript Scripting language –ECMAScript compliant –Client side vs. server side Syntactic rules –White space –Statement end: ; optional –Comments:
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
1 JavaScript 2 JavaScript. 2 Rollovers Most web page developers first use JavaScript for rollovers A rollover is a change in the appearance of an element.
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 8 Scott Marino.
Event JavaScript's interaction with HTML is handled through events that occur when the user or browser manipulates a page. When the page loads, that is.
1 CHAPTER 03: GOING FURTHER By Tharith Sriv. This chapter covers the following topics:  Flying texts or images  Using Comment  Using tag  Using …
CSS1 Dynamic HTML Objects, Collections & Events. CSS2 Introduction Dynamic HTML treats HTML elements as objects. Element’s parameters can be treated as.
Introduction to DHTML. What is DHTML? Dynamic HTML Just as Access is Dynamic Database environment Can have controls that respond to events Can have centralized.
Chapter 19 Creating and Processing HTML Forms. How HTML Forms Transmit Data name1=value1&name2=value2...&nameN =valueN GET or POST GET, an HTTP GET request,
1 Chapter 05: Creating Your Form. What is a Form? When you visit some websites you see a form. With this form, you are asked to complete, for example,
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 16 – Dynamic HTML: Event Model Outline 16.1Introduction 16.2Event ONCLICK 16.3Event ONLOAD.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 14 - Dynamic HTML: Event Model Outline 14.1 Introduction 14.2 Event onclick 14.3 Event onload 14.4.
Jaana Holvikivi 1 Introduction to Javascript Jaana Holvikivi Metropolia.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Project 8: Reacting to Events Essentials for Design JavaScript Level One Michael Brooks.
COS 125 DAY 20. Agenda Assignment 8 not corrected yet Assignment 9 posted  Due April 16 New course time line Discussion on Scripts 
OBJECTS What is an Object? Definition Properties Methods Events.
Web Programming Java Script & jQuery Web Programming.
5 th and 4 th ed: some from chapters 9, 12, 13 SY306 Web and Databases for Cyber Operations Slide Set #8: Dynamic HTML.
7. JavaScript Events. 2 Motto: Do you think I can listen all day to such stuff? –Lewis Carroll.
H.Melikyan/4910/031 Programming the World Wide Web JavaScript Dr.Hayk Melikyan Departmen of Mathematics and CS JavaScript and HTML Documents.
JavaScript II ECT 270 Robin Burke. Outline Functions Events and event handling Form validation.
JavaScript Events.
JavaScript Event Handlers. Introduction An event handler executes a segment of a code based on certain events occurring within the application, such as.
LESSON : EVENTS AND FORM VALIDATION -JAVASCRIPT. EVENTS CLICK.
Event Handlers Events are asynchronous. When an event occurs, JavaScript can execute code in response to the user’s action. This response to the user-initiated.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 14 - Dynamic HTML: Event Model Outline 14.1 Introduction 14.2 Event onclick 14.3 Event onload.
Chapter 4 Java Script - Part1. 2 Outlines Introduction to Java Script Variables, Operators and Functions Conditional statements JavaScript Objects Forms.
20-753: Fundamentals of Web Programming 1 Lecture 13: Javascript II Fundamentals of Web Programming Lecture 13: Javascript II.
CIS 228 The Internet 12/6/11 Forms and Validation.
SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Handling events from DOM objects.
Methods and Object Information. Some Document Methods.
JavaScript and HTML Simple Event Handling 11-May-18.
Chapter 14: DHTML: Event Model
JAVASCRIPTS AND HTML DOCUMENTS
JavaScript and HTML Simple Event Handling 19-Sep-18.
Chapter 14 - Dynamic HTML: Event Model
JavaScript Events.
Chapter 14 - Dynamic HTML: Event Model
JavaScript and Ajax (JavaScript Events)
JavaScript and HTML Simple Event Handling 26-Aug-19.
JavaScript and HTML Simple Event Handling 4-Oct-19.
Presentation transcript:

Събитието ONCLICK DHTML Event Model - ONCLICK alert( "Първи текст" ); опитайте да кликнете тук! <INPUT TYPE = "button" VALUE = "Разгледайте реакцията на това събитие!" ONCLICK = "alert( 'Нов текст' )";> DHTML – обработка на събития

Събитието ONLOAD DHTML Event Model - ONLOAD var seconds = 0; function startTimer() { // 1000 milliseconds = 1 second window.setInterval( "updateTime()", 1000 );} function updateTime() { seconds++; soFar.innerText = seconds; } Вече гледате тази страница: 0 DHTML – обработка на събития

Обработка на грешки – ONERROR DHTML Event Model - ONERROR window.onerror = handleError; function doThis() { alrrt( "hi" ); // сгрешен синтаксис} // предават се 3 аргумента: име на грешката, url на файла и // номер на ред function handleError( errType, errURL, errLineNum ) { // пише в status bar долу на страницата. window.status = "Error: " + errType + " on line " + errLineNum; // true канселира реакциите от браузъра. return true;} <INPUT ID = "mybutton" TYPE = "button" VALUE = "Click Me!" ONCLICK = "doThis()"> DHTML – обработка на събития

Oбектът event има 28 properties: offsetX, offsetY, clientX, button, propertyname, screenX, type.. Следене движението на мишката – ONMOUSEMOVE DHTML Event Model - ONMOUSEMOVE function updateMouseCoordinates() { coordinates.innerText = event.srcElement.tagName + " (" + event.offsetX + ", " + event.offsetY + ")"; } (0, 0) <IMG SRC = "mypicture.gif" STYLE = "position: absolute; top: 100; left: 100"> DHTML – обработка на събития

Oбработки на форми – ONFOCUS, ONBLUR DHTML Event Model - ONFOCUS и ONBLUR var helpArray = [ "Въведете името си тук", "Въведете вашия address в този блок, \ във формат - "Изберете този блок акохаресвате сайта.", "В този блок въведете коментар който искате да бъде прочетен.","С този бутон изпращате формата \ за обработка в сървърната страна", "С този бутон се изчисва формата", "Тази помощна област - TEXTAREA е място за context-sensitive \ help. Изберете някое поле или работете с TAB за да видите повече информация за него." ]; function helpText( messageNum ) { myForm.helpBox.value = helpArray[ messageNum ]; } DHTML – обработка на събития

Name: <INPUT TYPE = "text" NAME = "name" ONFOCUS = "helpText(0)" ONBLUR = "helpText(6)"> <INPUT TYPE = "text" NAME = " " ONFOCUS = "helpText(1)" ONBLUR = "helpText(6)"> Click here if you like this site <INPUT TYPE = "checkbox" NAME = "like" ONFOCUS = "helpText(2)" ONBLUR = "helpText(6)"> Искате ли коментар? <TEXTAREA NAME = "comments" ROWS = 5 COLS = 45 ONFOCUS = "helpText(3)" ONBLUR = "helpText(6)"> <INPUT TYPE = "submit" VALUE = "Изпрати" ONFOCUS = "helpText(4)" ONBLUR = "helpText(6)"> <INPUT TYPE = "reset" VALUE = "Reset" ONFOCUS = "helpText(5)" ONBLUR = "helpText(6)"> <TEXTAREA NAME = "helpBox" STYLE = "position: absolute; right: 0; top: 0" ROWS = 4 COLS = 45> Тук виждате context-sensitive help. DHTML – обработка на събития

Mеханизъм на придвижване на съобщенията DHTML Event Model - Event Bubbling function documentClick() { alert( "вие сте в документа" ); } function paragraphClick( value ) { alert( "вие сте в текста" ); if ( value ) event.cancelBubble = true; } document.onclick = documentClick; Кликнете тук! Опитайте тук - има друг път на събитието DHTML – обработка на събития

- DHTML поддържа над 60 събития от следните типове: clipboard events; data binding events; keyboard events; mouse events; други. - В Netscape процедурата е малко по-различна: if(window.Event ){ document.captureEvents(Event.CLICK) document.onclick = eventfunction } - В IE обектът window има дъщерен event, който е наличен по подразбиране при всяко възникване на събитие и съществува докато това събитие трае: document.onclick = eventfunction// не е нужно captureEvents(..) - В Netscape съобщенията се движат от обектите на върха на йерархията надолу. следователно, ако искате прихващането да е на по-долни нива, използвате методи за насочване на съобщенията – напр. routeEvent, handleEvent. DHTML – обработка на събития

DHTML – изброяване на наличните Events onabort Fires when the user aborts the download of an image. onactivate Fires when the object is set as the active element. onafterprint Fires on the object immediately after its associated document prints or previews for printing. onafterupdateFires on a databound object after successfully updating the associated data in the data source object. onbeforecopy Fires on the source object before the selection is copied to the system clipboard. onbeforecut Fires on the source object before the selection is deleted from the document. onbeforepaste Fires on the target object before the selection is pasted from the system clipboard to the document. onbeforeprint Fires on the object before its associated document prints or previews for printing. onbeforeupdate Fires on a databound object before updating the associated data in the data source object.

onblur Fires when the object loses the input focus. oncellchange Fires when data changes in the data provider. onchange Fires when the contents of the object or selection have changed. onclick Fires when the user clicks the left mouse button on the object. oncontextmenu Fires when the user clicks the right mouse button in the client area, opening the context menu. oncopy Fires on the source element when the user copies the object or selection, adding it to the system clipboard. oncut Fires on the source element when the object or selection is removed from the document and added to the system clipboard. ondataavailable Fires periodically as data arrives from data source objects that asynchronously transmit their data. ondatasetchanged Fires when the data set exposed by a data source object changes. ondatasetcompleteFires to indicate that all data is available from the data source object. ondblclick Fires when the user double-clicks the object.

ondrag Fires on the source object continuously during a drag operation. ondragend Fires on the source object when the user releases the mouse at the close of a drag operation. ondragenter Fires on the target element when the user drags the object to a valid drop target. ondragleave Fires on the target object when the user moves the mouse out of a valid drop target during a drag operation. ondragover Fires on the target element continuously while the user drags the object over a valid drop target. ondragstart Fires on the source object when the user starts to drag a text selection or selected object. ondrop Fires on the target object when the mouse button is released during a drag-and-drop operation. onerror Fires when an error occurs during object loading. onerrorupdate Fires on a databound object when an error occurs while updating the associated data in the data source object.

onfilterchange Fires when a visual filter changes state or completes a transition. onfocus Fires when the object receives focus. onfocusin Fires for an element just prior to setting focus on that element. onfocusout Fires for the current element with focus immediately after moving focus to another element. onhelp Fires if F1 key while the browser is the active window. onkeydown Fires when the user presses a key. onkeypress Fires when the user presses an alphanumeric key. onkeyup Fires when the user releases a key. onlayoutcomplete Fires when the print or print preview layout process finishes filling the current LayoutRect object with content from the source document. onload Fires immediately after the browser loads the object. OnlosecaptureFires when the object loses the mouse capture. OnmousedownFires when the user clicks the object with either mouse button. OnmouseenterFires when the user moves the mouse pointer into the object. OnmouseleaveFires when the user moves the mouse pointer outside the boundaries of the object. onmousemove Fires when the user moves the mouse over the object. onmouseout Fires when the user moves the mouse pointer outside the boundaries of the object. onmouseover Fires when the user moves the mouse pointer into the object. onmouseup Fires when user releases a mouse button while the mouse is over the object. onmousewheel Fires when the wheel button is rotated. onmove Fires when the object moves. onmoveend Fires when the object stops moving. onmovestart Fires when the object starts to move.

onpaste Fires on the target object when the user pastes data, transferring the data from the system clipboard to the document. onpropertychange Fires when a property changes on the object. onreadystatechange Fires when the state of the object has changed. onreset Fires when the user resets a form. onresize Fires when the size of the object is about to change. onresizeend Fires when the user finishes changing the dimensions of the object in a control selection. onresizestart Fires when the user begins to change the dimensions of the object in a control selection. onrowenter Fires to indicate that the current row has changed in the data source and new data values are available on the object. onrowexit Fires before the data source control changes the current row in the object. onrowsdelete Fires when rows are about to be deleted from the recordset. onrowsinserted Fires just after new rows are inserted in the current recordset. onscroll Fires when the user repositions the scroll box in the scroll bar on the object. onselect Fires when the current selection changes. onselectionchange Fires when the selection state of a document changes. onselectstart Fires when the object is being selected. onstart Fires at the beginning of every loop of the marquee object. onstop Fires when the user clicks the Stop button or leaves the Web page. onsubmit Fires when a FORM is about to be submitted. onunload Fires immediately before the object is unloaded.

- IE5 поддържа и механизъм за обработка на грешки trycatchthrow Използва се ако: -е необходима различна реакция за различните проблеми; -скрипта ще се изпълянва в сървър, където няма обект window, който да прихваща грешките. При възникване на грешка на блока catch се подава обект грешка (е) имащ 2 свойства – номер и описание. ( Преди анализа, обаче, номерът следва да се конвертират по определен начин (виж msdn.microsoft.com/scripting )). try { document.write("This statement works.") document.write(fakeO.use()) document.write("This statement does not work.")} catch (e) { strError=("An error occurred. The error number was "+e.number+". ") strError+=("The error message was \""+e.description+"\"") alert(strError)} DHTML – обработка на събития