This time it's a more advanced example.
Each time you press a button, it changes the background color.
A user-defined function
is linked to a button created in the body tag
so each time the user presses it, the onclick handler routes through to the linked user-defined function
and runs it.
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko"> |
|
|
|
|
|
<head> |
|
|
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" /> |
|
|
|
|
|
<title> User-defined Function 4</title> |
|
|
|
|
|
<script type="text/javascript"> |
|
|
//<!CDATA[ |
|
|
function bg_red() |
|
|
{ |
|
|
document.bgColor='red'; |
|
|
} |
|
|
function bg_white() |
|
|
{ |
|
|
document.bgColor='white'; |
|
|
} |
|
|
function bg_yellow() |
|
|
{ |
|
|
document.bgColor='yellow'; |
|
|
} |
|
|
function bg_green() |
|
|
{ |
|
|
document.bgColor='green'; |
|
|
} |
|
|
//]]]]]]> |
|
|
</script> |
|
|
|
|
|
</head> |
|
|
|
|
|
|
|
|
<body> |
|
|
|
|
|
<form method="post" action=""> |
|
|
<p> |
|
|
<input type="button" value="Reset" onclick="bg_white()" /> |
|
|
<input type="button" value="red" onclick="bg_red()" /> |
|
|
<input type="button" value="green" onclick="bg_green()" /> |
|
|
<input type="button" value="yellow" onclick="bg_yellow()" /> |
|
|
</p> |
|
|
</form> |
|
|
|
|
|
</body> |
|
|
|
|
|
</html> |
