会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132647个问题

<!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>
    <style>
        body{
            height: 2000px;
       background: linear-gradient('skyblue','pink');
       
        }
    </style>
</head>
<body>
    <span>密码:</span><input type="password"><span class="passwordSpan"></span>
   
    <script>
        var password=document.querySelector('input');
        var passwordSpan=document.querySelector('.passwordSpan');
        var flag=false;
       
        // document.body.onkeydown=function(){
        //     if(event.keyCode==20){
        //         flag=!flag;
        //     }
        //     if(flag){
        //         passwordSpan.innerHTML='现在是大写';
               
        //     }else{
        //      passwordSpan.innerHTML='现在是小写'
        //     }
        // }
        // document.body.onkeydown=function(){
        //     if(event.keyCode==40){
        //         window.onscroll=function(){
        //              var top=document.body.scrollTop||document.documentElement.scrollTop;
                   
        //         top=top-500;
        //         document.body.scrollTop=top;
        //         document.documentElement.scrollTop
        //         console.log(document.body.scrollTop||document.documentElement.scrollTop);
        //         }
               
        //     }
        //     if(event.keyCode==38){
        //         window.onscroll=function(){
        //              var top=document.body.scrollTop||document.documentElement.scrollTop;
        //         top=top+500;
        //         document.body.scrollTop=top;
        //         document.documentElement.scrollTop;
        //         console.log(document.body.scrollTop||document.documentElement.scrollTop);
        //         }
               
        //         }
        //     }
      window.onscroll=function(){
        console.log("top"+document.documentElement.scrollTop||document.body.scrollTop);
      }

        window.onkeydown=function(){
            console.log(event.keyCode);
            if(event.keyCode==65){
                var top=document.documentElement.scrollTop||document.body.scrollTop;
                top-=100;
                document.documentElement.scrollTop=top;

                document.body.scrollTop=top;
             
            }
            if(event.keyCode==68){
                var top=document.documentElement.scrollTop||document.body.scrollTop;
                top+=100;
                document.documentElement.scrollTop=top;

                document.body.scrollTop=top;
             
            }
        }
    </script>
</body>
</html>

老师 系统自带箭头滚动功能怎么搞 我设置了上箭头向上滚动200  还是2 来滚动

WEB前端全系列/第二阶段:JavaScript编程模块/浏览器模型(BOM) 257楼
WEB前端全系列/第二阶段:JavaScript编程模块/DOM模型 259楼
WEB前端全系列/第二阶段:JavaScript编程模块/字符串与数组 260楼
WEB前端全系列/第二阶段:JavaScript编程模块/DOM模型 261楼
WEB前端全系列/第二阶段:JavaScript编程模块/浏览器模型(BOM) 265楼
WEB前端全系列/第二阶段:JavaScript编程模块/字符串与数组 266楼

image.png

WEB前端全系列/第二阶段:JavaScript编程模块/DOM模型 267楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自定义右键菜单</title>
    <style>
        *{margin: 0;padding: 0;}
        ul{
            list-style: none;
            background-color: darkgray;
            min-width: 220px;
            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-color: orange;
            color: white;
        }
    </style>
</head>
<body>
<ul>
    <li>我想你了!</li>
    <li>你真的忍心离开本页面吗?</li>
    <li>去百度搜索页面中选中的内容</li>
    <li>输入内容然后去百度搜索</li>
</ul>
<textarea  cols="80" rows="20"></textarea>
<script>
    var ul=document.querySelector('ul');
    //系统右键菜单禁用事件【contextmenu】
    document.oncontextmenu = function (eve) {
        return false; //return false表示事件禁用
    }
    document.onmouseup=function (eve) {
        //eve.button能够判断鼠标用的是哪个按钮
        //0 左键   1滚轮    2右键
        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=='去百度搜索页面中选中的内容!'){
            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>

老师,我这个第三个功能实现不了,我也不知道是什么原因?

WEB前端全系列/第二阶段:JavaScript编程模块/面向对象编程 270楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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