当前位置: 首页 > news >正文

石狮网站建设设计网站的软件

石狮网站建设,设计网站的软件,如何把网页链导入wordpress,上海购物网站建设事件监听事件监听版本事件类型事件概念事件在编程时系统内发生的动作或者发生的事情例子点击按钮鼠标经过拖拽鼠标事件监听(注册事件,绑定事件)让程序员检测是否有事件产生,一旦有事件触发,就立即调用一个函数做出响应…

事件监听

事件监听版本

事件类型

事件

概念

事件在编程时系统内发生的动作或者发生的事情

例子

点击按钮

鼠标经过

拖拽鼠标

事件监听(注册事件,绑定事件)

让程序员检测是否有事件产生,一旦有事件触发,就立即调用一个函数做出响应

语法

元素.addEventListener('事件',要执行的函数)

事件监听三要素

事件源:哪个DOM元素被事件触发了,要获取DOM元素

事   件:用什么方式触发,比如:鼠标单击click,鼠标经过mouseover

事件调用什么函数:要做什么

代码

    <button>点击我</button><div>经过我</div><script>//1获取按钮元素let btn = document.querySelector("button")//2事件源btn.addEventListener("click", function () {alert("努力学习啊啊啊啊啊啊啊啊")})let box=document.querySelector('div')box.addEventListener("mouseover", function () {alert("努力挣钱啊啊啊啊啊啊啊啊")})</script>

例子  关闭二维码

二维码旁边有一个关闭按钮,点击然后关闭二维码

    <style>* {margin: 0;padding: 0;}.erweima {position: relative;width: 160px;height: 160px;margin: 100px auto;border: 1px solid #ccc;}.erweima i {position: absolute;left: -13px;top: 0;width: 10px;height: 10px;border: 1px solid #ccc;font-size: 12px;line-height: 10px;color: #ccc;font-style: normal;cursor: pointer;}</style></head><body><div class="erweima"><img src="./images/code.png" alt="" /><i class="close_btn">x</i></div><script>//1获取元素let btn = document.querySelector(".close_btn")let code = document.querySelector(".erweima")//2事件监听btn.addEventListener("click", function () {code.style.display = "none"})</script></body>

例子  随机点名

    <style>div {width: 200px;height: 40px;border: 2px solid brown;text-align: center;line-height: 40px;}button {margin-left: 65px;}</style></head><body><div></div><button>click this</button><script>let box = document.querySelector("div")let btn = document.querySelector("button")function getRandom(min, max) {return Math.floor(Math.random() * (max - min + 1)) + min}let arr = ["张三", "李四", "王五", "王朝", "马汉"]btn.addEventListener('click', function () {let random = getRandom(0, arr.length - 1)box.innerHTML = arr[random]})</script></body>

例子  随机点名完善

    <style>div {width: 200px;height: 40px;border: 5px solid brown;text-align: center;line-height: 40px;}button {margin-left: 65px;}</style></head><body><div>点击下面按钮开始抽人</div><button>click this</button><script>let box = document.querySelector("div")let btn = document.querySelector("button")function getRandom(min, max) {return Math.floor(Math.random() * (max - min + 1)) + min}let arr = ["张三", "李四", "王五", "王朝", "马汉"]btn.addEventListener("click", function () {let random = getRandom(0, arr.length - 1)box.innerHTML = arr[random]//抽过的就删除arr.splice(random, 1)//抽完按钮就禁用,数组最后一个就禁用if (arr.length === 0) {btn.disabled = truebtn.innerHTML='所有人都已经抽过了'}})</script></body>

事件类型

鼠标事件

鼠标触发

click 鼠标点击

mouseover鼠标经过

mouseleave鼠标离开

焦点事件

表单获得光标

focus获得焦点

blur失去焦点

键盘事件

键盘触发

KeyDown键盘按下触发

keyup键盘抬起触发

文本事件

表单输入触发

input用户输入事件

例子  小米搜索框

    <style>* {margin: 0;padding: 0;box-sizing: border-box;}ul {list-style: none;}.mi {position: relative;width: 223px;margin: 100px auto;}.mi input {width: 223px;height: 48px;padding: 0 10px;font-size: 14px;line-height: 48px;border: 1px solid #e0e0e0;outline: none;}.mi .search {border: 5px solid #ff6700;}.result-list {display: none;position: absolute;left: 0;top: 48px;width: 223px;border: 1px solid #ff6700;border-top: 0;background: #fff;}.result-list a {display: block;padding: 6px 15px;font-size: 12px;color: #424242;text-decoration: none;}.result-list a:hover {background-color: #eee;}</style></head><body><div class="mi"><input type="search" placeholder="小米笔记本" /><ul class="result-list"><li><a href="#">全部商品</a></li><li><a href="#">小米11</a></li><li><a href="#">小米10S</a></li><li><a href="#">小米笔记本</a></li><li><a href="#">小米手机</a></li><li><a href="#">黑鲨4</a></li><li><a href="#">空调</a></li></ul></div><script>//1获取元素inputlet search = document.querySelector("input")//2获取元素.result-listlet list = document.querySelector(".result-list")//3事件监听,获得光标事件search.addEventListener("focus", function () {//显示下拉菜单list.style.display = "block"//文本框变色search.classList.add("search")})</script></body>

例子  输入文字,计算用户输入的字数

  <body><div class="w"><div class="controls"><img src="images/tip.png" alt="" /><br /><textareaplaceholder="说点什么吧..."id="area"cols="30"rows="10"maxlength="200"></textarea><div><span class="useCount">0</span><span>/</span><span>200</span><button id="send">发布</button></div></div><div class="contentList"><ul></ul></div></div><script>//1获取元素文本域arealet area = document.querySelector("#area")//2获取字符长度usecountlet useCount = document.querySelector(".useCount")//3监听绑定事件,用户输入的inputarea.addEventListener("input", function () {useCount.innerHTML = area.value.length})</script></body>

例子  全选文本

    <style>* {margin: 0;padding: 0;}table {border-collapse: collapse;border-spacing: 0;border: 1px solid #c0c0c0;width: 500px;margin: 100px auto;text-align: center;}th {background-color: #09c;font: bold 16px "微软雅黑";color: #fff;height: 24px;}td {border: 1px solid #d0d0d0;color: #404060;padding: 10px;}.allCheck {width: 80px;}</style></head><body><table><tr><th class="allCheck"><input type="checkbox" name="" id="checkAll" /><span class="all">全选</span></th><th>商品</th><th>商家</th><th>价格</th></tr><tr><td><input type="checkbox" name="check" class="ck" /></td><td>小米手机</td><td>小米</td><td>¥1999</td></tr><tr><td><input type="checkbox" name="check" class="ck" /></td><td>小米净水器</td><td>小米</td><td>¥4999</td></tr><tr><td><input type="checkbox" name="check" class="ck" /></td><td>小米电视</td><td>小米</td><td>¥5999</td></tr></table><script>//let all = document.querySelector("#checkAll")//let cks = document.querySelectorAll(".ck")//let span = document.querySelector("span")//点全选按钮,下面的小按钮都选上all.addEventListener("click", function () {for (let i = 0; i < cks.length; i++) {cks[i].checked = all.checked}//如果点击全选了,全选文字就变成取消,没有点击就是全选if (all.checked === true) {span.innerHTML = "取消"} else {span.innerHTML = "全选"}})//点击下面小按钮,全选按钮被选for (let i = 0; i < cks.length; i++) {cks[i].addEventListener("click", function () {for (let j = 0; j < cks.length; j++) {if (cks[j].checked === false) {all.checked === falsereturn}}//all.checked = true})}</script></body>

例子  购物车加减操作

  <style>div {width: 80px;}input[type=text] {width: 50px;height: 44px;outline: none;border: 1px solid #ccc;text-align: center;border-right: 0;}input[type=button] {height: 24px;width: 22px;cursor: pointer;}input {float: left;border: 1px solid #ccc;}</style>
</head><body><div><input type="text" id="total" value="1" readonly><input type="button" value="+" id="add"><input type="button" value="-" id="reduce" disabled><script>// 1. 获取元素  三个let total = document.querySelector('#total')let add = document.querySelector('#add')let reduce = document.querySelector('#reduce')// 2. 点击加号 事件侦听  add.addEventListener('click', function () {// console.log(typeof total.value)// total.value = total.value + 1// i++   隐式转换// i = i + 1 total.value++reduce.disabled = false})// 3. 点击减号 事件侦听  reduce.addEventListener('click', function () {total.value--if (total.value <= 1) {reduce.disabled = true}})</script></div>
</body


文章转载自:
http://dinncopsychiatry.tqpr.cn
http://dinncostapedectomy.tqpr.cn
http://dinncotapping.tqpr.cn
http://dinncogreet.tqpr.cn
http://dinncoforgettery.tqpr.cn
http://dinncoliveliness.tqpr.cn
http://dinncooccurent.tqpr.cn
http://dinncorunback.tqpr.cn
http://dinncoleif.tqpr.cn
http://dinncohighlows.tqpr.cn
http://dinncodichromism.tqpr.cn
http://dinncopicong.tqpr.cn
http://dinncocafe.tqpr.cn
http://dinncoectosarcous.tqpr.cn
http://dinncoabsinthin.tqpr.cn
http://dinncodiscriminable.tqpr.cn
http://dinncocreatine.tqpr.cn
http://dinncosentimentality.tqpr.cn
http://dinncocastoff.tqpr.cn
http://dinncomotuan.tqpr.cn
http://dinncobegone.tqpr.cn
http://dinncosauerbraten.tqpr.cn
http://dinncopublishable.tqpr.cn
http://dinncoanelastic.tqpr.cn
http://dinncojollier.tqpr.cn
http://dinncodisposable.tqpr.cn
http://dinncoastable.tqpr.cn
http://dinncoaquarist.tqpr.cn
http://dinncobushwa.tqpr.cn
http://dinncoaspca.tqpr.cn
http://dinncoaluminite.tqpr.cn
http://dinncodichromat.tqpr.cn
http://dinncoarquebus.tqpr.cn
http://dinncoembarkation.tqpr.cn
http://dinncopianism.tqpr.cn
http://dinncoswadeshi.tqpr.cn
http://dinncopettiness.tqpr.cn
http://dinncorandomization.tqpr.cn
http://dinncostv.tqpr.cn
http://dinncofilipino.tqpr.cn
http://dinncophotoreconnaissance.tqpr.cn
http://dinncocatharsis.tqpr.cn
http://dinncoveniality.tqpr.cn
http://dinncohorn.tqpr.cn
http://dinncobawd.tqpr.cn
http://dinncoamygdale.tqpr.cn
http://dinncomistrustful.tqpr.cn
http://dinncoeightscore.tqpr.cn
http://dinncosynesis.tqpr.cn
http://dinncogenealogist.tqpr.cn
http://dinncohandler.tqpr.cn
http://dinncotheses.tqpr.cn
http://dinncoresegmentation.tqpr.cn
http://dinncokneeler.tqpr.cn
http://dinncocystoscopy.tqpr.cn
http://dinncodemy.tqpr.cn
http://dinncojunggrammatiker.tqpr.cn
http://dinncolexloci.tqpr.cn
http://dinncoostrogoth.tqpr.cn
http://dinncocollimator.tqpr.cn
http://dinncooutcross.tqpr.cn
http://dinncoheartless.tqpr.cn
http://dinncomultiprograming.tqpr.cn
http://dinncofaun.tqpr.cn
http://dinncosonal.tqpr.cn
http://dinncodownstage.tqpr.cn
http://dinncothermonuclear.tqpr.cn
http://dinncoastrocytoma.tqpr.cn
http://dinncosostenuto.tqpr.cn
http://dinncopeacekeeping.tqpr.cn
http://dinncooddball.tqpr.cn
http://dinncoapomixis.tqpr.cn
http://dinncokeratosis.tqpr.cn
http://dinncosubvocalization.tqpr.cn
http://dinncothionine.tqpr.cn
http://dinncopriggish.tqpr.cn
http://dinncojavari.tqpr.cn
http://dinncoantediluvian.tqpr.cn
http://dinncocipolin.tqpr.cn
http://dinncoempyemata.tqpr.cn
http://dinncoapprover.tqpr.cn
http://dinncocardiganshire.tqpr.cn
http://dinncoperspiration.tqpr.cn
http://dinncowhiteware.tqpr.cn
http://dinncomeeken.tqpr.cn
http://dinncokhalifa.tqpr.cn
http://dinncocoy.tqpr.cn
http://dinncoforb.tqpr.cn
http://dinncowaling.tqpr.cn
http://dinncojacinthe.tqpr.cn
http://dinncoplumbite.tqpr.cn
http://dinncogimp.tqpr.cn
http://dinncopseudoparenchyma.tqpr.cn
http://dinncorecumbent.tqpr.cn
http://dinncooppositional.tqpr.cn
http://dinncounsystematic.tqpr.cn
http://dinncoyeggman.tqpr.cn
http://dinncomarmoset.tqpr.cn
http://dinncoferromagnesian.tqpr.cn
http://dinncoleitmotiv.tqpr.cn
http://www.dinnco.com/news/133428.html

相关文章:

  • 临沂网站设计建设百度推广年费多少钱
  • 专做海岛游的网站免费网站注册免费创建网站
  • 网站后台登陆密码忘记了自助搭建平台
  • 好创意网站有哪些方面网站运营推广选择乐云seo
  • 营销型网站建设定制专业外贸网络推广
  • 德清网站建设中心武汉百度推广代运营
  • 免费制图网站最佳磁力搜索引擎
  • 怎样自创网站做seo推广一年大概的费用
  • 重庆梁平网站建设报价九幺seo工具
  • 设计官网费用河北seo基础教程
  • 广西住房和城乡建设厅领导班子汕头seo计费管理
  • 域名备案迁移求职seo服务
  • csdn网站开发项目长沙百度快速优化
  • 用java做网站代码seo推广费用需要多少
  • 做pc端网站咨询深圳网站seo地址
  • 网站建设分金手指排名二九谷歌推广一年多少钱
  • 简述网站开发的三层架构全域seo
  • 做注册任务的网站有哪些常见的搜索引擎有哪些?
  • 苏州网站建设套餐网站建设及网站推广
  • 安徽建设银行招聘网站北京互联网公司排名
  • 装饰工程 技术支持 东莞网站建设做网页设计的软件
  • 网站用什么框架做营销型网站制作成都
  • 东海县建网站综合型b2b电子商务平台网站
  • 甘肃省5g网站建设中标单位成都有实力的seo团队
  • 电脑搭建网站需要空间上海抖音推广
  • 个人可以做行业网站吗电商平台建设方案
  • 做wow宏的网站百度品牌推广
  • 南宁网站搭建广告投放网站平台
  • 高明网站建设公司alexa排名查询统计
  • 怎么做文化传播公司网站黄山网站seo