onclick = function(e) { js.Lib.alert(???Button Clicked!???); };
}
}
The element retrieved by getElementById() must be cast to the Button type because the function
returns an object of HtmlDom type that does not contain the definition for the onclick event (actually
the event is from FormElement but because btn is a Button it makes more sense this way). The cast is of
an unsafe type because it is not possible to use a proper cast on a typedef .
The container HTML page can be as simple as the following example. However, note how the script
element is inside the body element at the end of the page.
< html >
< head >
< title > Example < /title >
< /head >
< body >
< button id=???sbutton??? > Display Message < /button >
< script type=???text/javascript??? src=???main.js??? > < /script >
< /body >
< /html >
The solution in the preceding example suffers a very big limitation: The same event can be associated to
one and only one function at a time. This may not be a problem most of the time but you must be sure
that your script has exclusive access to those methods or unexpected cancellations may occur.
Pages:
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750