var alt = ""; for (var i = 1;i <= 5;i++){ var blank = " "; for (var j = 1;j <= 5-i;j++){ //空白三角形 blank+=" "; } var xing = ""; for (var m = 1;m <= 2*i-1;m++){ xing+="*"; } alt+=blank+xing+"</br>"; } //console.log(alt); document.write(alt);
老师这段代码在控制台上显示的是等腰三角形,为什么在页面上用document.write为什么不显示空白的三角形,我也用</br>换行了呀,请老师帮我看一下,感谢!
if(a < b && a < c){
console.log("a最小" + a);
}else if(b < c)
{
console.log("b最小" + b);
}else{
console.log("c最小" + c);
}
这些写法可以吗?
else if(){ }和else { if () }有什么区别?
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>自定义右键菜单</title> <style> *{margin: 0;padding: 0;} ul{ list-style: none; background-color: darkgray; min-width: 220px; display: inline-block; position: absolute; display: none; } ul li{ height: 30px; line-height: 30px; padding: 5px 20px; cursor: pointer;/*光标变小手*/ transition:0.3s; } ul li:hover{ background-color: orange; color: white; } </style> </head> <body> <ul> <li>我想你了!</li> <li>你真的忍心离开本页面吗?</li> <li>去百度搜索页面中选中的内容</li> <li>输入内容然后去百度搜索</li> </ul> <textarea cols="80" rows="20"></textarea> <script> var ul=document.querySelector('ul'); //系统右键菜单禁用事件【contextmenu】 document.oncontextmenu = function (eve) { return false; //return false表示事件禁用 } document.onmouseup=function (eve) { //eve.button能够判断鼠标用的是哪个按钮 //0 左键 1滚轮 2右键 if (eve.button==2){ ul.style.display='inline-block'; //设置鼠标点击的位置 ul.style.left=eve.clientX+'px'; ul.style.top=eve.clientY+'px'; }else { //关闭菜单 ul.style.display='none'; } } //点击某一个菜单选项时触发的事件(事件委托) ul.onmousedown=function (eve) { if (eve.target.innerHTML=='我想你了!'){ alert('那就去吧,她在北京三区'); }else if (eve.target.innerHTML=='你真的忍心离开本页面吗!'){ if (confirm('你真的忍心离开本页面吗!')){ window.close(); } }else if (eve.target.innerHTML=='去百度搜索页面中选中的内容!'){ var resukt=document.getSelection().toString(); window.open('http://www.baidu.com/s?wd='+resukt); }else{ var result=prompt('输入内容然后去百度搜索'); window.open('http://www.baidu.com/s?wd='+result); } } </script> </body> </html>
老师,我这个第三个功能实现不了,我也不知道是什么原因?
09history对象代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div>history对象</div> <a href="./10history跳转.html">history</a> <button id="btn1">前进</button> <script> var btn1 = document.getElementById("btn1"); btn1.onclick = function(){ //history.forward(); 前进一个页面 history.go(1); } </script> </body> </html>
10histoty跳转代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div>跳转新页面</div> <button id="btn2">后退</button> <script> var btn2 = document.getElementById("btn2"); btn2.onclick = function(){ history.back(); } </script> </body> </html>
老师,第一次打开页面,点击前进按钮,没有反应,不能像视频里直接跳转到10history跳转页面。只能先点击链接跳转,后退,然后再点击前进才有反应。这是因为浏览器的原因吗?
想问老师,通过for循坏我们可以使字符串用大驼峰命名,例如:
把watches tv——Watches Tv
那在开发场景中我们会不会遇见
把watches tv——WatcHes TV这样的场景呢(把两个单词任中任意的字母变为大写),如果有 我们应该用什么样的方法
老师我想问一下
选项 视频说c 文档给d 到底哪个对
防抖,是利用清除定时器(定时器不清楚的时候判断为真)节流是利用时间差(第一次valid为ture 以下简称为状态和真,我们做第一次判断,真取反是假,就不执行return,执行下一段代码,状态赋值为假,定时器是延迟执行(也就意味着你出连续滚动时第二次的滚动的时候你第一次的定时器还没触发),第二次执行的代码就是拿到 闭包保存的 假 状态 来做判断,当然,这次的判断就会执行return 而return的作用就会让后面的代码不执行,那我们什么时候执行打印呢,就是我们第一次定时器delay延迟事件到了的时候,打印,并且我们才会把 状态 赋值为 真, 这样在下一次执行取反就会回到 状态 真 这样的循环 ( 什么时候循环结束,你不一致滚动滚动条的时候结束 ))
function throttle(fn,delay){ let valid = true return function() { if(!valid){ //休息时间 暂不接客 return false } // 工作时间,执行函数并且在间隔期内把状态位设为无效 valid = false setTimeout(function(){ fn() valid = true; }, delay) } } function showTop () { var scrollTop = document.documentElement.scrollTop; console.log('滚动条位置:' + scrollTop); } window.onscroll = throttle(showTop,300)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>我要成为像马斯克一样的人!</title> </head> <body> <script> function roll() { var docTitle=document.title; var titleArr=docTitle.split(''); titleArr.push(titleArr.shift()); var newTitle=titleArr.join(''); document.title=newTitle; }; setInterval ('roll()',500); </script> </body> </html>
这个地方换成自己定义的名字后怎么就完成不了?
就是c 文档里还给的d 楼下也指明了 你们回答的还不改 666
<!DOCTYPE html> <html lang="en"> <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> .div1{ background-color: blue; width: 500px; height: 500px; } .div2{ background-color:pink; width: 200px; height: 200px; margin: 150px; } </style> </head> <body> <div class="div1">这是div1 <div class="div2">这是div2</div> </div> <button class="btn">删除</button> <script> var div1=document.querySelector('.div1'); var div2=document.querySelector('.div2'); var btn=document.querySelector('.btn'); function fun1(){ console.log('这是div1'); } function fun3(){ console.log('这是div1第二次'); } function fun2(){ console.log('这是div2'); } div1.attachEvent('click',fun1); div2.attachEvent('click',fun2); div1.attachEvent('click',fun3); </script> </body> </html>
老师,他说不支持这个方法
感觉老师这里讲的不清除,但是我这里自己梳理了一下,希望能帮到大家
老师,我这里这样写,为什么浏览器显示为其他,而不是I=2呢?
<script> var s=85; if (s>90) { document.write("I=4") } else if(90>s>80 ) { document.write("I=3") } else if(80>s>70 ) { document.write("I=2") } else if(70>s>60 ) { document.write("I=1") } else { document.write("其他") } </script>
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637