Monday, April 8, 2013

My solution to chapter 11 exercises of JavaScript Step by Step 2e

1. Create a webpage that contains an onclick event handler connected to a link using a
DOM 0 inline event. The event handler should display an alert stating “You Clicked
Here”.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <a href="#" onclick="alert('You Clicked Here');">This is a link</a>
</body>
</html>


2. Change the webpage created in Exercise 1 to use the newer style of event handling
shown in ehandler.js (in the companion content) and connect the same click/onclick
event to display the alert created in Exercise 1.

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="../../Scripts/ehandler.js" type="text/javascript"></script>
</head>
<body>
    <a id="link1" href="#">This is a link</a>

    <script type="text/javascript">
        function showAlert() {
            alert("You Clicked Here");
        };
        var link1 = document.getElementById("link1");
        EHandler.add(link1, "click", showAlert);       
    </script>
</body>
</html>


3. Create a webpage with a link to http://www.microsoft.com. Make that link open in a
new tab.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <a href="http://www.microsoft.com." target="_blank">http://www.microsoft.com</a>
</body>
</html>

No comments:

Post a Comment