。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
这个undefined的写法不严谨啊,
var arr=[1,23,4,5,undefined,7];
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document节点练习</title> <!--<style type="text/css"> ul{ list-style: none;margin: 0;padding: 0; } ul li{ display: inline-block;width: 100px;height: 30px;line-height: 30px;text-align: center;background-color: #0086b3; } li a{ } li:hover{ background-color: #0077aa; } li a:hover{ color:red; } </style>--> <style> li:hover{background-color: #b3d4fc} li a:hover{color:red} </style> </head> <body> <!--<ul> <li><a href="#">首页</a></li> <li><a href="#">新闻</a></li> <li><a href="#">军事</a></li> <li><a href="#">娱乐</a></li> </ul>--> <script> var arr=["首页","新闻","军事","娱乐"] var ulText=document.createElement('ul'); var ulText_style= document.createAttribute('style'); ulText_style.value="list-style: none;margin: 0;padding: 0;"; ulText.setAttributeNode(ulText_style); for(var i=0;i<arr.length;i++){ var liText=document.createElement('li'); var liText_style= document.createAttribute('style'); liText_style.value='display:inline-block;width:100px;height:30px;line-height:30px;\ text-align:center;margin-left:5px'; liText.setAttributeNode(liText_style); var aText=document.createElement('a'); var aText_style= document.createAttribute('style'); aText_style.value="text-decoration: none;"; aText.setAttributeNode(aText_style); aText.innerHTML=arr[i]; liText.appendChild(aText); ulText.appendChild(liText); } document.body.appendChild(ulText); var arr2 = ['cnode社区也切换到let\'s encrypt了','【深圳】nodeparty 2016.04.09总结','国内nodejs2015','展望nodejs 2016','基础javascript']; var ul1 = document.createElement('ul'); var ul1_style = document.createAttribute('style'); ul1_style.value = 'height: 30px;list-style: none;padding: 0;margin: 0;'; ul1.setAttributeNode(ul1_style); document.body.appendChild(ul1); for (var j =0;j<arr2.length;j++){ var li1 = document.createElement('li'); var li1_style = document.createAttribute('style'); li1_style.value = "height: 30px;line-height: 30px;text-align: left;border-bottom: 1px solid gainsboro;"; li1.setAttributeNode(li1_style); var a1 = document.createElement('a'); a1.innerHTML = arr2[j]; li1.appendChild(a1); ul1.appendChild(li1); } </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>window对象</title> </head> <body> <button>跨域传输</button> <script> // open('http://www.baidu.com'); // close(); // var but =document.querySelector('button'); // but.onclick=function(){ // var iframe = document.createElement('iframe'); // iframe.src='name.html'; // iframe.style.display='none'; // document.body.appendChild(iframe); // iframe.onload=function(eve){ // var iframeWindowName = eve.target.contentWindow.name; // console.log(iframeWindowName); // } // } var but= document.querySelector('button'); but.onclick=function(){ var iframe= document.createElement('iframe'); iframe.src='name.html';//加载保存了信息的页面 iframe.style.display='none'; document.body.appendChild(iframe); //当iframe加载完毕,意味着window.name的内容已经被赋予完毕 iframe.onload=function(eve){ var iframeWindowName=eve.target.contentWindow.name; // console.log( iframeWindowName); eval(iframeWindowName); console.log(num); } } </script> </body> </html>
跟着老师的代码敲的,无奈报错,于是把老师的代码拿过来 仍然报错,如图
var num1 = 10;
var num2 = 20;
console.log(num1++);//10
console.log(++num1 + num2);//32
为什么是32
<!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 num=10; window.name='var num=10;'; </script> </body> </html>
与主代码在同一级目录下
<!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> <br> <button>解析数据</button> <script> var but=document.querySelector('button'); function dataParse(outInfo){ var obj={}; var inforStr=outInfo; //获取?后面的数据 var realInfo=inforStr.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(window.location.search); console.log(decodeURIComponent(dataObj)); } </script> </body> </html>
老师麻烦给看看是哪里错了第二个问题这个outInfo是怎么回事?不明白 谢谢老师这个是beixi赋值给username,还有age跟sex没有赋值吧。
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637