单击事件的响应函数和响应函数的调用函数的区别

来源:互联网 发布:二次规划最优化 编辑:程序博客网 时间:2024/06/06 09:20
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    <title></title>    <script type="text/javascript">        function ShowMyName()        {            alert('Lucas');        }     </script></head><body>       <input type="button" value="单击" id="t1" onclick="alert('A good Man:' ); ShowMyName()"/>    <img src="8.jpg" /></body></html>
这种写法Onclick后面就是相应函数,里面可以写很多函数,其中ShowMyName()只是其中的一个函数,所以showMyName
是相应函数的调用函数。
情形二:
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    <title></title>    <script type="text/javascript">        function InitEnvent()        {            var btn = document.getElementById('t1');            btn.onclick = ShowHello;//事件响应函数        }        function ShowHello()        {            alert('hello');            alert(this.value);//事件响应函数的调用函数        }    </script></head><body onload="InitEnvent()">       <input type="button" value="单击" id="t1"  />    <img src="8.jpg" /></body></html>
0 0