請問這句中$('p').click(function(e) { alert(e.target.innerHTML)的function(e)中的e指什么?還有e.target.innerHTML中的target是什么意思呢?
<html>
<head>
? ? <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
? ? <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
? ? <style type="text/css">
? ? p {
? ? ? ? color: red;
? ? }
? ? </style>
</head>
<body>
? ? <p>P元素1,默認給綁定一個點擊事件</p>
? ? <p>P元素2,默認給綁定一個點擊事件</p>
? ? <button id="bt1">點擊刪除 p 元素</button>
? ? <button id="bt2">點擊移動 p 元素</button>
? ? <script type="text/javascript">
? ? $('p').click(function(e) {
? ? ? ? alert(e.target.innerHTML)
? ? })
? ? var p;
? ? $("#bt1").click(function() {
? ? ? ? if (!$("p").length) return; //去重
? ? ? ? //通過detach方法刪除元素
? ? ? ? //只是頁面不可見,但是這個節點還是保存在內存中
? ? ? ? //數據與事件都不會丟失
? ? ? ? p = $("p").detach()
? ? });
? ? $("#bt2").click(function() {
? ? ? ? //把p元素在添加到頁面中
? ? ? ? //事件還是存在
? ? ? ? $("body").append(p);
? ? });
? ? </script>
</body>
</html>
2017-02-18
e是點擊的這次事件,target是事件作用的對象也就是p標簽