<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/html"> <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 dataParse(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 dataObj=dataParse(document.location.search); console.log(dataObj); } </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> <style> div { width: 30px; height: 30px; background-color: pink; position: absolute; line-height: 15px; text-align: center; } </style> <body> <input type="range" min="0" max="100" value="50"> <div id="box"></div> <script> var input = document.querySelector("input") var div = document.getElementById('box'); var flag = false; input.onmousedown = function () { console.log("(x,y):(" + event.clientX + "," + event.clientY + ")"); } </script> </body> </html>
老师,我是什么步骤错了,鼠标事件一直没效果,是没获取到input吗
<!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> document.write('hello<br/>world'); document.write('<br/>'); document.write('hello' + '<br/>' + 'world'); alert('hello\nworld'); alert('hello' + '\n' + 'world'); </script> </body> </html>
老师 您好 我想问一下 代码里的<br/> 和\n 加不加引号有区别吗
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>自定义右键菜单</title> <style> *{margin: 0;padding: 0} ul{ list-style: none; width: 190px; height: 125px; background-color: darkgrey; position: absolute; display: none; } ul li{ border: 1px solid skyblue; padding: 4px; cursor: pointer; transition: 0.5s; } ul li:hover{ background-color: skyblue; color: #fff; } </style> </head> <body> <ul> <li>我想尚学堂了!</li> <li>您真要离开此页面吗?</li> <li>去百度搜索页面中的内容</li> <li>输入内容后去百度搜索</li> </ul> <textarea cols="80" rows="20"></textarea> <input type="text"> <script> let ul=document.querySelector('ul'); //禁用系统的右键 document.oncontextmenu=function (eve) { return false; //return false 表示禁用事件 }; //鼠标抬起出现鼠标右键菜单 document.onmouseup=function (eve) { //eve.button 判断鼠标点的是那个按键 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=='去百度搜索页面中的内容'){ let result = document.getSelection().toString(); open('https://www.baidu.com/s?wd='+result); }else {eve.target.innerHTML=='输入内容后去百度搜索'}{ let value = document.querySelector('input').value; open('https://www.baidu.com/s?wd='+value); } } </script> </body> </html>
怎么会取不到input框的值,去百度搜索呢,老师
var timer1=null; var timer2=null; var timer3=null; timer1=setInterval(function(){console.log('这是第1个定时器')},2000); timer2=setInterval(function(){console.log('这是第2个定时器')},2000); timer3=setInterval(function(){console.log('这是第3个定时器')},2000); console.log(timer1); console.log(timer2); console.log(timer3) //clearInterval(2); clearInterval(timer1);
还有,按老师的代码,为啥视频中先输出的是123 ,而我这先输出的是234 ,这是什么情况
老师,为啥ul采用事件委托时用 onclick,第三个效果就没法实现呢?
function yangcolor(){ var str="0123456789abcdef";//定义取值范围 var color="#"; for(var i=0;i<6;i++){ var num=Math.floor(Math.random()*str.length); color+=str[num] } console.log(color); }
老师,为啥我运行不出来?
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <style> li{background-color: skyblue} li:hover{ background-color: #ff6700; } </style> <body> <button id="button1">获取元素</button> <button id="button2">设置元素</button> <button id="button3">删除元素</button> <script> var div1=document.createElement('div'); div1.style.cssText='width:100%;position:relative;background:red;'; var div2=document.createElement('div'); div2.style.cssText='width:80%;position: absolute;left: 50%;transform: translateX(-50%)'; document.body.appendChild(div1); var arr=['首页','军事','科技','新闻','游戏']; var ul=document.createElement('ul'); ul.style.cssText='margin:0;padding:0;list-style;text-align: center;background:pink;'; for (var i=0;i<arr.length;i++){ var li=document.createElement('li'); li.style.cssText='display: inline-block; width: 100px;height: 30px; line-height: 30px;\ text-align: center; margin-left:5px'; var a=document.createElement('a'); a.style.cssText=' text-decoration: none;color: white;'; a.innerHTML=arr[i]; li.appendChild(a); ul.appendChild(li); } div2.appendChild(ul); div1.appendChild(div2); document.body.appendChild(div1); var button=document.querySelector('div'); document.querySelector('#button1').onclick=function () { console.log( button.getAttribute('style')); }; document.querySelector('#button2').onclick=function () { button.setAttribute('style','display:none'); }; document.querySelector('#button3').onclick=function () { button.removeAttribute('style'); } </script> </body> </html>
老师为啥我div1颜色设置不出来
<script>
function count() {
let arr = [];
for(let i = 0;i < 3;i++) {
arr.push(function() {
return i*i;
})
}
return arr
let a = count();
console.log(a[i]());
</script>
为什么这样调用后出来的结果是0,1,4,而不是视频中那样所有结果都一样呢?
这个lis[i].onmouseleave写在里面和外面有什么区别呢?我觉得因为用到了i所以应该写在里面但是写在外面好像也没问题。
var x=1; var y=1; document.write(x+"</br>"); document.write(y+"</br>"); for (var z=1;z<10;z++){ var i=x; var x=y; var y=i+x; z++; document.write(y+"</br>") } </script>
老师,这里的z为什么不是小于6?
老师这个判断一个数是奇数还是偶数为什么要用===,而不是==呢?
===不是用来比较数值和类型的吗?
而==不是单独用来比较数值的吗?
老师为什我的WebStorm用ie打不开呢,用法子打开吗,其它的可以的
老师能不能简单的理解为对象是具体的类是抽象的呢
function timesTampToTime(timestamp) { var d = new Date(timestamp); var year = d.getFullYear() + '-'; var month = d.getMonth() + 1 + '-'; var day = d.getDate() + ' '; var hours = d.getHours() + ':'; var minute = d.getMinutes() + ':' var second = d.getSeconds(); second >=10 ? d.getSeconds() : ('0' + d.getSeconds()); return year + month + day + hours + minute + second; } var result = timesTampToTime(1642529707845); console.log(result)
2022-1-19 2:15:7
为什么0没有添加上呢
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637