1练习中问题一
老师金字塔是怎么做出的呢,我的代码是在哪一处有了问题的呢
代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>for循环联系打印</title> </head> <body> <script> /* /!*打印5行5列的矩形 * * * * * * * * * * * * * * * * * * * * * * * * * *!/ for (var j=1;j<5;j++){ //外层循环控制行 for (var i=1;i<5;i++){ //内层循环控制列 document.write("*") } document.write("<br/>"); }*/ /*打印5行5列的矩形 * * * * * * * * * * * * * * * for (var j=1;j<5;j++){ //外层循环控制行 for (var i=1;i<=j;i++){ //内层循环控制列 document.write("*") } document.write("<br/>"); }*/ /*打印5行5列的矩形 * * * * * * * * * * * * * * * */ var alt=""; for (var i=1;i<=5;i++){ //控制行 var blank="" for (var j=1;j<=5-i;j++){ //空白三角形 blank+="" } var stars=""; for (var m=1;m<=2*i-1;m++){ stars+="*"; } alt+=blank+stars+"\n"; } console.log(alt); </script> </body> </html>
运行图.
作业图
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>原型</title> </head> <body> <script> /* //原型 function func() {} func.prototype.name = '张三'; func.prototype.age=18; func.prototype.sex='男'; var obj= new func(); console.log(obj); function People(){} //console.log(People.prototype.constructor); console.log(People.prototype); var beixi=new People(); console.log(beixi.__proto__); */ function People(){} var peo1=new People(); var peo2=new People(); People.prototype.frineds=['张三','李四','王五','找刘']; peo1.frineds.pop(); console.log(peo1.frineds); console.log(peo2.frineds); </script> </body> </html>
为什么我的俩个都删除了呢
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>构造函数</title> </head> <body> <script> function Car(lun1,lun2,lun3,lun4,ability) { this.lun1=lun1; this.lun2=lun2; this.lun3=lun3; this.lun4=lun4; this.ability=ability; } var myCar1=new Car('左前轮1','右前轮1','左后轮1','右后轮1',function () { console.log("能跑1"); }); var myCar2=new Car('左前轮2','右前轮2','左后轮2','右后轮2',function () { console.log("能跑2"); }); console.log(myCar1); console.log(myCar2); </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> <ul> <li></li> <li></li> <li></li> <li></li> </ul> <script> var arr=['首页','游戏','直播','视频']; var ul=document.querySelector('ul'); var li=document.querySelectorAll('li'); for(var i=0;i<arr.length;i++){ li[i].innerHTML=arr[i]; } ul.onclick=function(){ li.style.cssText='background-color:red'; } </script> </body> </html>
老师哪里写错了吗
老师,您好,这个hash表,为什么存入object引用速度更快呢? 在object里面它不应该是键名么,是怎么返回值的呢
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>数据解析</title> </head> <body> <form action="" method="get"> 姓名:<input type="text" name="userName"></br> 年龄:<input type="text" name="age"></br> 性别:<input type="text" name="sex"></br> <input type="submit"> </form> <button>解析数据</button> <script> var but=document.querySelector("button"); function f(outInfo){ var obj={}; var infoStr=outInfo; var realInfo=infoStr.slice(1); var proArr= realInfo.split("&"); for(var i=0;i < proArr.length;i++){ var tempArr =proArr[i].split("="); obj[tempArr[0]]=tempArr[1]; } return obj; } but.onclick=function () { var infoStr=f(document.location.search); console.log(infoStr); } </script> </body> </html>
这种应该没有什么吧
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>自定义左键菜单案例</title> <style type="text/css"> *{ padding: 0; margin: 0; } ul{ list-style: none; background: #9f9f9f; min-width: 250px; 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: #b3d4fc; color: #ffffff; } </style> </head> <body> <ul> <li>一</li> <li>二</li> <li>三</li> <li>四</li> <li>去百度搜索页面中选中的内容</li> </ul> <textarea cols="80" rows="30"></textarea> <script> var ul =document.querySelector("ul"); //禁用右键菜单 document.oncontextmenu=function (eve) { return false; }; document.onmouseup=function (eve) { //判断鼠标用的哪个按钮 // 0 左键 1 滑轮 2 右键 if(eve.button==2){ ul.style.display="inline-block"; //设置鼠标点击的位置 ul.style.left=eve.clientX+"px"; ul.style.right=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>
这种应该没有错吧,感觉和视频里有点不一样
<!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 str1='你好,佛可栏,回家吃饭了,'; var newStr1=str1.replace(/[佛][可][栏]/g,'张账务'); var newStr2=str1.replace(/佛可栏/g,'张账务'); console.log(newStr1); console.log(newStr2); </script> </body> </html>
老师,这两种写法没区别吧
老师,蓝色圈着的不明白,为什么Mycar的原型的构造函数原型直接就证明是object的实例呢?
老师 原型和原型链啥关系 说的我有点懵????????????????
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> <div class="div1">div1 <div id="div2">div2</div> </div> <span>这是span标签</span> <script> var div1=document.querySelector('.div1'); var div2=document.querySelector('#div2'); var span=document.querySelector('span'); console.log(document.body.firstChild);//#text (body后面有回车) console.log(document.body.lastChild);//script console.log(span.firstChild.nodeValue); console.log(span.innerHTML);//也可以获取到span里面的文字内容,value不可以 console.log(span.value); </script> </body> </html>
老师您好,我想我问一下这个value是只能获取input那种在网页输入的值么
console.log(span.value);
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>js_名称解释_变量</title> </head> <body> <!-- script标签表示脚本,可在标签中写js代码。也可通过src属性引入外部脚本文件,注意:可以写在html的任意位置,但一般写在body的最后。1.语句,描述:以分号结尾的表达式。2.变量,描述:表示可以发生改变的量,语法:变量一般采用var来声明,举例var num=10; --> <script> var a=prompt("请输入您的成绩:"); if(a>60){ document.write("第五名!"); }else if(a>70){ document.write("第四名!"); }else if(a>80){ document.write("第三名!"); }else if(a>90){ document.write("第二名!"); }else if(a=100){ document.write("第一名!"); }else{ document.write("不及格!"); } </script> </body> </html>
//修改 obj.name='张先生'; obj['height']='170cm'; console.log(obj);
这两个obj,修改方式什么时候是
obj.name='张先生'
什么时候是
obj['height']='170cm';
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>什么是对象</title> </head> <body> <script> /*类和对象 对象是实实在在存在的;汽车不是对象是一个类,某一个实际的车才是对象*/ var beixi={ userName:'贾先生', userAge:18, ability:function(){ console.log('吃了睡睡了吃'); } }; var lishishi={ userName:'李思思', userAge:22, ability:function(){ console.log('卖萌'); } }; var result=(beixi.ability()); console.log(result); </script> </body> </html>
老师我想调用对象里的ability,想要直接输出吃了睡睡了吃,为什么打印台还出现了undefined
13分27秒 老师为啥 不封装函数之前获取url字符串的时候是用window.location.search,使用封装函数的时候,调用者要调用函数的时候传入参数为啥使用document.location.search?一样吗
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637