//點擊登錄按鈕顯示登錄層addEvent(login_btn,"click",showLogin);//點擊關閉按鈕隱藏登錄層// 執(zhí)行代碼addEvent(close,"click",hideLogin);為什么這個里面調(diào)用showLogin()和hideLogin()函數(shù)不用加小括號()***************************************************以下代碼區(qū)域****************************************************<!doctype html><html><head><meta charset="UTF-8"><title>Document</title><style>* {margin: 0;padding: 0;}.head {font-size: 12px;padding: 6px 0 0 10px;}#login_box {width: 300px;height: 150px;background: #eee;border: 1px solid #ccc;position: absolute;left: 50%;top: 50%;margin-left: -150px;margin-top: -75px;display: none;}#login_box p {height: 20px;border-bottom: 1px solid #ccc;font-size: 12px;padding: 6px 0 0 5px;font-weight: bold;}#close {width: 14px;height: 14px;background: url(close.png) no-repeat;position: absolute;right: 4px;top: 6px;}</style><script>window.onload = function() {var login_btn = document.getElementById('login'),login_box = document.getElementById('login_box'),close = document.getElementById('close');// 封裝添加事件監(jiān)聽程序function addEvent(ele, type, handler) {// 執(zhí)行代碼if (ele.addEventListener) {ele.addEventListener(type, handler, false);} else if (ele.attachEvent) {ele.attachEvent("on" + type, handler);} else {ele["on" + type] = handler;}}// 顯示登錄層函數(shù)function showLogin() {// 執(zhí)行代碼login_box.style.display = "block";}// 隱藏登錄層函數(shù)function hideLogin() {// 執(zhí)行代碼login_box.style.display = "none";}//點擊登錄按鈕顯示登錄層// 執(zhí)行代碼addEvent(login_btn,"click",showLogin);//點擊關閉按鈕隱藏登錄層// 執(zhí)行代碼addEvent(close,"click",hideLogin);}</script></head><body><div class="head">親,您好!<input type="button" value="登 錄" id="login"></div><div id="login_box"><p>用戶登錄</p><span id="close"></span></div></body></html>
為什么沒加括號可以,加了反而不行
ABOUTYOU
2022-07-20 15:11:44