会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132647个问题
WEB前端全系列/第九阶段:HTML5新特性模块/(旧)H5新特性 46楼
WEB前端全系列/第九阶段:HTML5新特性模块/(旧)H5新特性 47楼

02后台操作cookie.rar

浏览器打印出来的结果是把PHP文件的文本内容

image.png

WEB前端全系列/第九阶段:HTML5新特性模块/(旧)H5新特性 48楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
    <script type="text/javascript" src="https://api.map.baidu.com/api?v=3.0&ak=FbonyatSbRvrD6W2ApVIpz5BGT9wE18a"></script>

    <title>Document</title>
    <style type="text/css">  
        html{height:100%}    
        body{height:100%;margin:0px;padding:0px}    
        #container{height:500px;width: 700px; border: 1px solid black;}    
    </style> 
</head>
<body>
    <div id="container"></div> 
    <button>加载</button>
    <script>
        var btn=document.querySelector('button');
        btn.onclick=function(){
            var map = new BMap.Map("container");    
var point = new BMap.Point(113.26512290418745, 23.154485582798717);    
map.centerAndZoom(point, 15);    
map.addControl(new BMap.NavigationControl());//平移缩放
//默认标注
// map.addEventListener('click',function(eve){
//     var tempMarker = new BMap.Marker(eve.point);        // 创建标注    
// map.addOverlay(tempMarker);  
// }


//------------------------自定义图标-------------------
var temPoint = new BMap.Point(113.26552290418745, 23.154485582798717);
var myIcon = new BMap.Icon("imgs/标注.gif", new BMap.Size(50, 50), {    
        // 指定定位位置。   
        // 当标注显示在地图上时,其所指向的地理位置距离图标左上    
        // 角各偏移10像素和25像素。您可以看到在本例中该位置即是   
        // 图标中央下端的尖角位置。    
        anchor: new BMap.Size(10, 25),    
        // 设置图片偏移。   
        // 当您需要从一幅较大的图片中截取某部分作为标注图标时,您   
        // 需要指定大图的偏移位置,此做法与css sprites技术类似。    
        imageOffset: new BMap.Size(-30, 10)   // 设置图片偏移    
    });      
    // 创建标注对象并添加到地图   
    var Mymarker = new BMap.Marker(temPoint, {icon: myIcon});    
    map.addOverlay(Mymarker);    
        }
    </script>
</body>
</html>

我的自定义图片怎么加载不了出来

WEB前端全系列/第九阶段:HTML5新特性模块/(旧)H5新特性 49楼
WEB前端全系列/第九阶段:HTML5新特性模块/(旧)H5新特性 51楼

3.png

老师控制台看不到经纬度,其他效果没问题这是为什么啊?前两节也是,控制台根本看不懂

WEB前端全系列/第九阶段:HTML5新特性模块/HTML5新特性 52楼
WEB前端全系列/第九阶段:HTML5新特性模块/HTML5新特性 54楼

<!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>
</head>
<body>

    <video src="" height="500px" width="500px" id="video"></video>
    <canvas id="canvas" width="500px" height="500px"></canvas>
    <button class="btn1" onclick="getMedia()">视频</button>
    <button class="btn2" onclick="takePhone()">拍照</button>
    <script>
      /*调用用户设备
      *调用摄像头  移动端会给用户选择 1打开相册 2打开摄像头  pc端直接调用摄像头

      *调用麦克风  直接调用

      *调用方法getUserMedia();
      * Navigator.mediaDevices.getUserMedia(constraints,successCallback,errorCallback)
      
      * constraints 设备类型
      {
      video:true  //s摄像头
      Audio: true //麦克风 
      }
      */
     function getMedia(){
         var video=document.getElementById('video');
         /*
         Navigator.mediaDevices.getUserMedia  该方法返回一个promise对象
         当该方法对象成功返回后 的回掉函数会带有一个MediaStream对象作为其参数
         then()是promise的异步方法,当then()前的所有方法执行完毕后在执行then()方法避免数据没有获取到
          */
         var constraints={
             video:{height:500,width:500},
             audio:true
         }
        var promise=navigator.mediaDevices.getUserMedia(constraints)
        promise.then(function(MediaStream){
            video.srcObject=MediaStream;
            video.play();
        })
     }

    </script>
</body>
</html>

老师不行喔 报错  是因为我电脑没摄像头吗  但是手机打不开

image.png

WEB前端全系列/第九阶段:HTML5新特性模块/(旧)H5新特性 55楼
WEB前端全系列/第九阶段:HTML5新特性模块/(旧)H5新特性 56楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>cookie案例</title>
    <style>
        .loginRegistDiv{
            text-align: center;
            padding: 15px;
            border: 1px solid black;
            width: 300px;
            min-height: 30px;
        }
        .welcomeDiv{
            text-align: center;
            padding: 15px;
            border: 1px solid black;
            width: 300px;
            min-height: 30px;
            display: none;
        }
        .nickNameSpan{
            color: green;
            font-size: 22px;
            font-weight: bold;
        }
    </style>
</head>
<body>
 <div class="loginRegistDiv">
     <lable for="userName">
         <span>用户名:</span><input type="text" id="userName" placeholder="请输入用户名">
     </lable><br><br>
     <lable for="password">
         <span>密&nbsp;&nbsp;&nbsp;码:</span><input type="text" id="password" placeholder="请输入密码">
     </lable><br><br>
     <button class="loginBtn">登录</button>
     <button class="registBtn">注册</button>
 </div>
<div class="welcomeDiv">
    欢迎回来,尊敬的:
    <span class="nickNameSpan">哈哈哈</span>
    <br><br>
    <button class="exitBtn">注销登录</button>
</div>
 <script>
     //页面逻辑
     ;(function () {
         var loginBtn=document.querySelector('.loginBtn');
         var userNameInput=document.querySelector('#userName');
         var passwordInput=document.querySelector('#password');
         var welcomeDiv=document.querySelector('.welcomeDiv');
         var loginRegistDiv=document.querySelector('.loginRegistDiv');
         var nickNameSpan=document.querySelector('.nickNameSpan');
         var exitBtn=document.querySelector('.exitBtn');
         //表示一个自动登录的功能
         function getCookie() {
             var cookie=document.cookie;
             var cookieArr=cookie.split(';');
             // console.log(cookieArr);//得到的是数组 (2) ["uname=beixi", " userId=120123"]
             var finalObj={};
             for (var i=0;i<cookieArr.length;i++){
                 //trim()是去除空格
                 var tempArr=cookieArr[i].trim().split('=');
                 //console.log(tempArr);//(2) ["uname", "beixi"]  (2) ["userId", "120123"]
                 finalObj[tempArr[0]]=tempArr[1];
             }
             return finalObj;
         }
         console.log(getCookie());
         var cookieObj=getCookie();
         //判断cookie存储的nickName是否存在
         if (cookieObj.nickName!=undefined){
             if (cookieObj.nickName.length!=0){
                 loginRegistDiv.style.display='none';
                 welcomeDiv.style.display='block';
                 nickNameSpan.innerHTML=cookieObj.nickName;
             }
         }
         loginBtn.onclick=function () {
            //发送Ajax请求
             var xhr=new XMLHttpRequest();
             xhr.onreadystatechange=function () {
                 if (xhr.readyState==4){
                     if (xhr.status==200){
                         var data=xhr.responseText;
                         if (data.infoCode==0){
                             loginRegistDiv.style.display='none';
                             welcomeDiv.style.display='block';
                             nickNameSpan.innerHTML=data.nickName;
                         }
                     }
                 }
             };
             var formData=new FormData();
             formData.append('uname',userNameInput.value);
             formData.append('upass',passwordInput.value);
             xhr.open('post','7-cookie案例后台.php',true);
             xhr.send(formData);
         };
         //退出登录按钮
         exitBtn.onclick=function () {
             userNameInput.value='';
             passwordInput.value='';
             loginRegistDiv.style.display='block';
             welcomeDiv.style.display='none';
             //清除cookie
             var expires=new Date(new Date().getTime()+1).toGMTString();
             document.cookie='nickName=beixi,expires='+expires;
         }
     })();
 </script>
</body>
</html>

php:
 <?php
$success=array('msg'=>'ok');
$userName=$_POST['uname'];
$password=$_POST['upass'];
//连接数据库
try{
$con=new PDO('mysql:host=localhost;dbname=beixidb','root','');
   if($con){
      //添加辅助设置
      mysqli_query($con,'set names utf8');
      mysqli_query($con,'set character_set_client utf8');
      mysqli_query($con,'set character_set_results utf8');
      $sql="select * from userinfo where 1";
      $result=$con->query($sql);
      //解析查询的结果
      if($result->num_rows>0){
        $info=[];
        for($i=0;$row=$result->fetch_assoc();$i++){
          $info[$i]=$row;
        }
        //$success['infoCode']=$info;//拿到数据了
        //得到解析数组后,判断用户发来的内容是否存在于数据库中
        $flag=0;//只要执行break,就变为1,否则一直为0
        for($j=0;$j<count($info);$j++){
         //判断是否与当前条目的用户名相同
         if($info[$j]['username']==$username){
            //如果相同,继续判断是否是当前条目的密码
            if($info[$j]['password']==$password){
                $success['infoCode']=0;
                $flag=1;
                break;
            }
         }
        }
        if($flag==0){
        $success['infoCode']=1;
        }
      }else{
        $success['infoCode']=1;
      }
      }else{
      //向前台返回信息
      //0代表登录成功,1代表登录失败,2代表数据库连接失败
      $success['infoCode']=2;
      }
}catch(PDOException  $err){
echo '出现错误信息:'.$err->getMessage();
}
setcookie('nickName','beixi',time()+3600*24);
//回馈前端表示登录成功,使用状态码infoCode  0表示成功  1表示失败
$success['infoCode']=0;
$success['nickName']='beixi';
echo json_encode($success);
?>

老师,我总觉得我的优点问题,但是又找不到代码出错的地方,老师帮忙看看呗,谢谢老师

WEB前端全系列/第九阶段:HTML5新特性模块/(旧)H5新特性 57楼
WEB前端全系列/第九阶段:HTML5新特性模块/HTML5新特性 58楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>多个小球运动</title><style>canvas{border: 1px solid;}</style>
</head>
<body>
    <canvas width="500px" width="400px">对不起你的浏览器不支持canvas</canvas>
    <script>
        var mycanvas=document.querySelector('canvas');
        var ctx=mycanvas.getContext('2d');
        function Circle(){
            this.r=Math.floor(Math.random()*20+6);
            this.x=Math.floor(Math.random()*(500-this.r));
            this.y=Math.floor(Math.random()*(400-this.r));
            this.dx=Math.floor(Math.random*10);
            this.dy=Math.floor(Math.random*8);
            this.color='rgb('+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+')';
        }
        Circle.prototype.yd=function(){
            this.x+=this.dx;
            if(this.x<=this.r){
                this.dx=-this.dx
            }else if(this.x>=500-this.r){
                this.dx=-this.dx
            }
            this.y+=this.dy;
            if(this.y<=this.r){
                this.y=-this.dy
            }else if(this.y>=400-this.r){
                this.dy=-this.dy
            }
        }
       Circle.prototype.abs=function(){
           ctx.beginPath();
           ctx.arc(this.x,this.y,this.r,0,2*Math.PI);
           ctx.fillStyle=this.color;
           ctx.fill();
           ctx.closePath();
         

       }
       var arr=[];
           for(var i=0 ;i<4;i++){
               arr[i]=new Circle();
           }
           var timer=setInterval(function () {
               ctx.clearRect(0,0,mycanvas.width,mycanvas.height)
               for(var i=0;i<arr.length;i++){
                   arr[i].yd();
                   arr[i].abs();

               }
           },40)

    </script>
</body>
</html>

老师为啥我的球显示不了

WEB前端全系列/第九阶段:HTML5新特性模块/(旧)H5新特性 60楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637