代码示例:(标识:eg_js_function_3)
<!DOCTYPE html>
<html> 
<head> 
<script> 
function myfunction(txt) { 
  document.getElementById("demo").innerHTML = txt
} 
</script> 
</head> 
<body>

<p>单击其中一个按钮时,将调用一个函数。该函数将显示传递给它的参数。</p>

<form> 
  <input type="button" onclick="myfunction('Good Morning!')" value="In the Morning"> 
  <input type="button" onclick="myfunction('Good Evening!')" value="In the Evening"> 
</form> 

<p id="demo"></p>

</body> 
</html>
运行结果: