<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>编写一个带有hover样式的导航栏,要求采用鼠标事件实现</title> </head> <body> <script> var arr = ["首页","军事","新闻","我们"]; var ul = document.createElement('ul'); var ul_style = document.createAttribute('style'); ul_style.value="list-style: none;margin: 0px;padding: 0px;"; ul.setAttributeNode(ul_style); for (var i = 0;i<arr.length;i++){ var li = document.createElement("li"); var li_style = document.createAttribute("style"); li_style.value="display: block;float: left;width: 150px;height: 50px;" + "line-height: 50px;text-align: center;background:pink;margin-left:100px;"; li.setAttributeNode(li_style); var a = document.createElement("a"); var a_style = document.createAttribute("style"); a_style.value="text-decoration: none;"; a.setAttributeNode(a_style); a.innerHTML=arr[i]; li.appendChild(a); ul.appendChild(li); } document.body.appendChild(ul); //li事件 var li = document.querySelector('li'); li.onmouseover = function () { li.style.background='yellow'; }; li.onmouseout = function () { li.style.background="pink"; }; //超链接事件 var a = document.querySelector('a'); a.onmouseover = function () { a.style.color="white"; }; a.onmouseleave = function () { a.style.color="#ccc"; }; </script> </body> </html>
老师,你好,请问一下怎么设置属性能让每个li元素都有鼠标事件,我这样设置的只有第一个li产生了鼠标事件?
创建类就类似于封装一个创建对象的函数,用new关键
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>DOM0级事件</title> </head> <style> .div1{ width: 200px; height: 200px; background-color:pink; } .div2{ width: 100px; height: 100px; background-color:blue; margin: 25px auto; } </style> <body> <div class="div1" >div1 <div class="div2">div2</div> </div> <script> var div1=document.querySelector('div1'); var div2=document.querySelector('div2'); /* DOM0级事件 描述:在js脚本中,直接通过on+事件名的方式绑定的事件称为DOM0级事件 语法:元素.on+事件名=function(){} */ div2.onclick=function(){ console.log('这是div2'); } </script> </body> </html>
老师,为什么我的会提示这个错误
为什么控制台显示的不对呢
var grade = 100; switch (grade) { case grade>=90:{console.log("成绩优秀");} break; case grade<90 && grade>=80:{console.log("成绩良好");} break; case grade<80 && grade>=70:{console.log("成绩一般");} break; default:{console.log("成绩较差,望继续努力!");} }
老师您好,我这段程序为什么执行出来的结果直接跳到最后一句了?
老师,像这种images[ i ]的读取内容的方法,是因为images是一个对象类型吗?
老是为什么这个j不用闭包
OCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> *{padding: 0;margin: 0} ul{ list-style: none;background-color: azure;width: 220px; display: none;position: absolute;} li{ height: 30px;line-height: 30px;padding: 5px 10px; } li:hover{background-color: orange} </style> </head> <body> <ul> <li>真的要离开么</li> <li>去尚学堂</li> <li>搜索选中的内容</li> <li>搜索输入的内容</li> </ul> <textarea cols="30" rows="10"></textarea> <script> window.oncontextmenu=function () { return false } var ul=document.querySelector('ul'); document.onmouseup=function (eve) { if (eve.button==2){ ul.style.display='block'; ul.style.top=eve.clientY+'px'; ul.style.left=eve.clientX+'px'; }else {ul.style.display='none'} } ul.onclick=function (eve) { if (eve.target.innerHTML=='去尚学堂'){ alert('那就去吧') } else if (eve.target.innerHTML=='真的要离开么'){ if (confirm('真的要离开么')){window.close()} }else if (eve.target.innerHTML=='搜索选中的内容'){ var ret=document.getSelection().toString(); window.open('http://www.baidu.com/s?wd='+ret) // console.log(ret) }else { var ret=prompt('搜索输入的内容'); window.open('http://www.baidu.com/s?wd='+ret) } } </script> </body> </html>
window.close()无法关闭当前窗口
var ret=document.getSelection().toString();
为什么不是Sum.prototype = Object.create(Sxt);而是Sum.prototype = Object.create(Sxt.prototype);
老师,这里用console.log和alert为什么显示不一样,用alert则提示框显示11 12 。
<script> var a=10; console.log(++a); console.log(a); alert(a++); alert(a); </script>
以下代码,按了一下监盘也触发了多次,这是验证结论,触发多次的原因是什么?
<script> var timer1=null; var timer2=null; var timer3=null; timer0=setInterval('show("对滴!")',1000); timer2=setInterval(function(){console.log("hello");},1000); timer3=setInterval(function(){console.log("world");},1000); console.log(timer1);//1 console.log(timer2);//2 console.log(timer3);//3 function show(tmp){console.log("小白大可爱"+tmp);} // clearInterval(timer1); //clearInterval(1); </script>
老师您好,我想请问间隔调用的返回的数字队列,是一定会从1开始吗?我这部分打印出来的数字队列返回值就从几开始的都有
老师 clickBtn方法里的this指向谁
//将一段字符串变为驼峰命名法 //helloworld——HelloWorld var str = "hello-world"; var arr = str.split("-") var result = ""; console.log(arr) for(var i = 0;i<=arr.length;i++){ var world = arr[i]; result += world.charAt(0).toUpperCase()+world.slice(1); } console.log(result);
老师帮忙看一下 为什么控制台中无法打开,出现报错
这里每次循环变量j都会重新赋值为1对吧,
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637