<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>自定义右键菜单案例</title> <style> ul{width: 200px;background: #f8f8f8;border: 1px solid #cccc;list-style: none;padding: 0;display: none;position: absolute;} ul li{height: 30px;line-height: 30px;font-size: 14px;padding-left: 10px;cursor: pointer;} ul li:hover{background-color: teal;} </style> </head> <body> <textarea cols="30" rows="10"></textarea> <ul> <li>你是谁?</li> <li>你确定要离开本页面吗?</li> <li>选中的内容跳转到百度搜索</li> <li>输入的内容跳转到百度搜索</li> </ul> <script> //系统右键菜单禁用事件【contextmenu】 document.oncontextmenu = function (eve) { return false; //return false表示事件禁用 }; //鼠标右键点击任意位置显示右键菜单 var ul = document.querySelector('ul'); document.onmouseup = function(eve){ //eve.button可以判断用的是鼠标的哪一个按钮 //左键是0,滚轮是1,右键是2 //console.log(eve.button); if(eve.button == 2){ //设置鼠标点击的位置 //记住记住记住,必须给‘px’ ul.style.left = eve.clientX + 'px'; ul.style.top = eve.clientY + 'px'; ul.style.display = 'block'; }else{ ul.style.display = 'none'; } } //采用事件委托,点击每一个选项时触发的事件 ul.onclick = function(eve){ if(eve.target.innerHTML == '你是谁?'){ alert('我是我') }else if(eve.target.innerHTML == '你确定要离开本页面吗?'){ //判断点击的是确定还是取消 if(confirm(eve.target.innerHTML == '你确定要离开本页面吗?')){ window.close(); } }else if(eve.target.innerHTML == '选中的内容跳转到百度搜索'){ var result = document.getSelection().toString();//getSelection()获取选中的内容,然后转成字符串就可以搜索了 window.open('http://www.baidu.com/s?wd=' + result); }else{ var result1 = prompt('搜索什么'); window.open('http://wwww.baidu.com/s?wd=' + result1); } } </script> </body> </html>
老师,我的第三个只能跳到百度,不能直接选中搜索
<script> var alt=""; for (var i=1;i<=5;i++){ //代表行 var blank=""; for (var j=1;j<=5-i;j++){ //代表空格 blank+=" "; } var star=""; for (var s=1;s<=2*i-1;s++){ star+="*"; } alt+=blank+star+"<br/>"; } document.write(alt); </script>
老师为什么我的不是等腰三角形呀,那个blank哪也弄了空格了,我弄不出那个题的效果,老师帮忙看看吧
老师,我这个怎么num怎么还是获取不到,按照视频的案例写的
<script> var day=prompt("请输入一个数字"); switch (day){ case 1:{document.write("星期一");} break; case 2:{document.write("星期二"); } break; case 3:{document.write("星期三");} break; case 4:{ document.write("星期四"); } break; case 5:{document.write("星期五");} break; // case 6:{ // document.write("星期六"); // } break; // case 7:{ // document.write("星期日"); // } break; default:{document.write("星期天");} } </script>
老师为啥我输入这些数字的任何一个出来都是星期天呀
QQ截图20201130165548.png
如果按第一种写法,意思就是把所有的关键字都默认当成字符串,用方括号写就默认把关键字还当作关键字?
<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开始吗?我这部分打印出来的数字队列返回值就从几开始的都有
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>node方法2</title> </head> <body> <div> <div>div1</div> <div id="div2">div2</div> </div> <button id="but">点我</button> <script> var div=document.querySelector('div'); var div1=document.querySelector('.div1'); var div2=document.getElementById('div2'); var but=document.getElementById('but'); but.onclick.function () { var textNode=document.createTextNode('收藏'); but.replaceChild(textNode,but.firstChild); but.setAttribute('disabled','disabled'); } </script> </body> </html>
老师,为什么报错了呢?哪里错了?
老师,我把 i ++ 换成 ++ i 可以吗?这两个啥区别?
<!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> var a=prompt("输入x") var a=prompt("输入y") if (x<y) { alert("最小值:"+y); } else if (x==y) { alert("两者相等"); } else { alert("最小值:"+x); } </script> </body> </html>
我这代码哪里出问题了,为啥只提示输入框却不提示结果?
<!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> <button>跨域传输</button> <script> //如果想要另一个页面的信息,必须先加载这个页面 var btn=document.querySelector("button"); btn.onclick=function(){ var iframe=document.createElement("iframe"); iframe.src="02跨域传输.html";//加载保留信息的页面 iframe.style.display="none"; document.body.appendChild(iframe); //当iframe加载完毕,意味着window.name的内容已经被赋予完毕 iframe.onload=function(eve){ var iframeWindow= eve.target.contentWindow.name; console.log(iframeWindow);//打印的是放在name里面的全部字符串 eval(iframeWindow);//将字符串解析成代码使用 console.log(num);//这里就可以用其他界面的内容 } } </script> </body> </html>
老师这个是什么问题
<!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> var bb='111'; function aa() { alert(bb); } aa(); var bbb='111'; function aaa() { alert(bbb);//函数内变量提升 var bbb='test'; alert(bbb); var ccc='test1'; alert(ccc); } aaa(); </script> </body> </html>
老师 为什么第一个bb是111
第二个bbb是undefined呢
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document节点属性</title> </head> <body> <script> /* console.log(document.doctype); console.log(document.documentElement); console.log(document); 二、返回文档的固有属性 1.document.documentURL console.log(document.documentURI); 2.URL 注意:本属性是只读(无法修改内容) document.URL='http://www.baidu.com';//无效 console.log(document.URL); 3.domain */ console.log(document.domain); </script> </body> </html>
老师,为什么出来是这样的呢?
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document节点属性</title> </head> <body> <script> /* */ console.log(document.doctype); console.log(document.documentElement); console.log(document); </script> </body> </html>
老师,下面那三行是什么意思呢?(代码没有问题)
<!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> // 返回值:[函数执行结束后]返回到[原本程序中函数所在的位置],用来替代整个函数的[结果],被称为函数的返回值。 function add(a, b) { return a + b; } function add(a, b) { console.log(a + b); } add(1, 4); </script> </body> </html>
老师 您好 我不太懂这个返回值的意思
那怎么调用有返回值的函数add 在控制台上输出结果呢
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document节点练习</title> </head> <body> <script> var docTitle=document.title; //把标题字符串切割成数组 var titleArr=docTitle.split(''); //把数组的第一个元素删除,然后添加到最后 titleArr.puth(titleArr.shift()); //把数组合并为字符串 var newTitle=titleArr.join(''); document.title=newTitle; </script> </body> </html>
老师,我的为什么报错了呢?
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637