<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <script> var season=prompt('请输入十以下的数字'); switch (season) { case '1'||'2'||'3':{ alert('winter'); } break; case '5'||'4':{ alert('spring'); } break; case '6'||'7'||'8':{ alert('summer'); } break; case '9'||'10'||'0':{ alert('automn'); } break; default:{ alert('meiyou'); } } </script> </body> </html>
老师用||或不可以进行选择吗v
一元二元运算符是怎么区分的?
<script> //打印出1,1,2,3,5,8,13 var num1=1; var num2=1; document.write(num1+"<br/>"); document.write(num2+"<br/>"); var i=0; while (i<5){ //把num1的值先保存起来,如果不保存的话,就会每次都是和num1=1相加 var temp=num1; //第二次的第一个值是第一次的第二个值 新的num1是上一次的num2 num1=num2; //新的num2是上一次的(num1+temp) num2=temp+num2; document.write(num2+"<br/>"); i++; } </script>
老师我想着,把num1赋值给temp,到最后,不是也是num1=1和其他相加吗,老师,我不太懂while循环里面的
var i=1; while(i<=100) { document.write(i+"<br/>"); i=i+1; }
老师,document和console有啥区别?这俩个应该什么时候用?
求助:老师,为什么我打印出来第一个是undefined,第二个虽然也是undefined,但是展开从里边的prototype是能够找到2的。。
<script> function People(name,ability,eyesNum){ this.name = name; this.ability = ability; var secret = '我爱你'; this.getSecret = function(){ console.log(secret); }; this.eyesNum = eyesNum; } People.prototype.eyesNum = 2; var shiwentao = new People('施文涛',function(){ console.log('脱发'); }); var huojinxing = new People('霍金星',function(){ console.log('cute'); }); console.log(shiwentao.eyesNum); console.log(huojinxing);</script>
老师,对于document.body.clientWidth/document.body.clientHeight
document.body.offsetWidth/document.body.offsetHeight
document.body.scrollWidth/document.body.scrollHeight
document.body.scrollTop/document.body.scrollLeft
这几个有点不太明白,我理解是offsetWidth=clientWidth+border;可是在变网页窗口的时候,offsetWidth比clientWidth小。不知道为什么我这么写之后,网页就不显示div了。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> </style> <body style="height: 1000px"> <div style="background: #0d3349;width: 300px;height: 2000px"></div> </body> <script type="text/javascript"> window.onload=function(){ document.write("网页可见区域宽:"+document.body.clientWidth+"</br>"); document.write("网页可见区域高client:"+document.body.clientHeight+"</br>"); document.write("网页可见区域宽:"+document.body.offsetWidth+"</br>"); document.write("网页可见区域高offset:"+document.body.offsetHeight+"</br>"); document.write("网页正文全文宽:"+document.body.scrollWidth); document.write("网页正文全文高:"+document.body.scrollHeight); document.write("网页被卷去的高:"+document.body.scrollTop); document.write("网页被卷去的左:"+document.body.scrollLeft); document.write("网页正文部分上:"+window.screenTop); document.write("网页正文部分左:"+window.screenLeft); document.write("网页正文部分上:"+window.screenX); document.write("网页正文部分左:"+window.screenY); document.write("屏幕分辨率的高:"+window.screen.height); document.write("屏幕分辨率的宽:"+window.screen.width); document.write("屏幕可用工作区高度:"+window.screen.availHeight); document.write("屏幕可用工作区宽度:"+window.screen.availWidth); document.write("浏览器高度:"+window.outerHeight+"</br>"); document.write("浏览器宽度:"+window.outerWidth+"</br>"); document.write("浏览器内页面可用高度:"+window.innerHeight+"</br>"); document.write("浏览器内页面可用宽度:"+window.innerWidth); } </script> </head> </html>
item没有赋值咋知道item是否等于arr.shift()
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <script type="text/javaScript" src="./hello.js"></script> <script> var num = 3; if (num === 3) { console.log(num++);//3 var result = num++; console.log(result)//4 } </script> </body> </html>
老师,您好,请问一下,为什么这个语句,++在后也能重新赋值,结果为4的?
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .boderRed{ border: 2px solid red; } .boderGreen{ border: 2px solid green; } .colorRed{ color: red; } .colorGreen{ color: green; } </style> </head> <body> <form action="" method="post"> <span class="">用户:</span> <input type="text"> <span></span> <button>提交</button> </form> <script> var input=document.querySelector('.username'); var span=document.querySelector('.usernameSpan'); var btn=document.querySelector('button'); //自动获取焦点 input.focus(); input.onblur=function(){ if(input.value.length==11){ this.className='boderGreen'; span.className='colorGreen'; span.innerHTML='正确'; }else{ this.className='boderRed'; span.className='colorRedn'; span.innerHTML='错误'; } } btn.onclick=function(){ input.focus(); input.blur(); input.focus(); } </script> </body> </html>
老师为啥错误的时候 不会再获取焦点了?
老师,我这怎么回事,404
检查了几遍还是这样
老师,我不明白为什么title的类型为字符串呢,其他的都为对象。
<div id="d" style="width: 100px;height: 100px;background: red">文本</div>
<script> var t=document.getElementById("d"); console.log(typeof(t)); console.log(typeof(document.title)); console.log(typeof(document.head)); console.log(typeof(document.body)); </script>
<!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>
老师,为什么我的会提示这个错误
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637