💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
常见的鼠标事件 |鼠标事件 | 触发条件 | | --- | --- | | onclick | 鼠标点击左键触发 | | onmouseover | 鼠标经过触发 | | onmouseout | 鼠标离开触发 | | onfocus | 获得鼠标焦点触发 | | onblur | 失去鼠标焦点触发 | | onmousemove | 鼠标移动触发 | | onmouseup | 鼠标弹起触发 | | onmousedown | 鼠标按下触发 | ``` // 点击按钮显示当前时间。 <button>显示当前时间</button> <div>某个时间</div> <script> let myDiv = document.querySelector("div"); let myBtn = document.querySelector("button"); myBtn.onclick = function () { // innerText 修改元素内容 myDiv.innerText= getDate(); }; function getDate() { var date = new Date(); var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDay(); var dates = date.getDate(); var weekday = ["星期天","星期一","星期二","星期三","星期四","星期五","星期六"]; var hour = date.getHours(); var minute = date.getMinutes(); var seconds = date.getSeconds(); return "今天是 " + year + "年" + month + "月" + dates + "日" + "," + weekday[day] + ",时间是:" + hour +":" + minute +":" +seconds; } </script> ``` `innerText` 和 `innerHtml`区别 ``` // html标签当做是字符显示 object.innerText = "<strong>哈哈哈</strong>"; // html标签“哈哈哈”显示粗体 object.innerHtml= "<strong>哈哈哈</strong>"; ```