会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133651个问题
JAVA 全系列/第一阶段:AI驱动的JAVA编程/变量、数据类型、运算符 29866楼

HelloWorld.zip

servletdemo.zip

老师好 上面是我sevlet的web项目和setvlet文件,下面是我访问这个servlet时报的错,老师您给看看 ,我的web.xml文件和servlet文件哪编写的有问题。谢谢老师。

servlet图1.pngservlet图2.png

JAVA 全系列/第六阶段:JavaWeb开发/Servlet技术详解(旧) 29868楼

servletdemo.zip

老师好 上面是我sevlet的web项目,下面是我访问这个servlet时报的错,老师您给看看 ,我的web.xml文件和servlet文件哪编写的有问题。谢谢老师。

servlet图1.pngservlet图2.png

JAVA 全系列/第六阶段:JavaWeb开发/Servlet技术详解(旧) 29869楼
JAVA 全系列/第十一阶段:分布式RPC调用和分布式文件存储/FastDFS 29870楼
JAVA 全系列/第一阶段:AI驱动的JAVA编程/变量、数据类型、运算符 29871楼
Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/Flask视图基础和URL 29874楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编写一个带有hover样式的导航栏,要求采用鼠标事件实现</title>
</head>
<body>
    <script>
        var arr = ["首页","军事","新闻","我们"];
        var ul = document.createElement('ul');
        var ul_style = document.createAttribute('style');
        ul_style.value="list-style: none;margin: 0px;padding: 0px;";
        ul.setAttributeNode(ul_style);
        for (var i = 0;i<arr.length;i++){
            var li = document.createElement("li");
            var li_style = document.createAttribute("style");
            li_style.value="display: block;float: left;width: 150px;height: 50px;" +
                "line-height: 50px;text-align: center;background:pink;margin-left:100px;";
            li.setAttributeNode(li_style);
            var a = document.createElement("a");
            var a_style = document.createAttribute("style");
            a_style.value="text-decoration: none;";
            a.setAttributeNode(a_style);
            a.innerHTML=arr[i];
            li.appendChild(a);
            ul.appendChild(li);
        }
        document.body.appendChild(ul);
        
        //li事件
        var li = document.querySelector('li');
        li.onmouseover = function () {
            li.style.background='yellow';
        };
        li.onmouseout = function () {
            li.style.background="pink";
        };
        
        //超链接事件
        var a = document.querySelector('a');
        a.onmouseover = function () {
            a.style.color="white";
        };
        a.onmouseleave = function () {
            a.style.color="#ccc";
        };
    </script>
</body>
</html>

老师,你好,请问一下怎么设置属性能让每个li元素都有鼠标事件,我这样设置的只有第一个li产生了鼠标事件?

image.png

WEB前端全系列/第二阶段:JavaScript编程模块/浏览器模型(BOM) 29875楼
JAVA 全系列/第五阶段:网页编程和设计/Javascript 语言(旧) 29876楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自定义右键菜单案例</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        ul{
            width: 200px;
            background-color: papayawhip;
            position: absolute;
            display: none;
            list-style: none;
        }
        li{
            height: 30px;
            line-height: 30px;
            padding: 5px;
            cursor: pointer;
        }
        li:hover{
            background-color: pink;
        }
    </style>
</head>
<body>
<pre>
提示框综合案例【自定义右键菜单】
要求:
(1)菜单选项一、弹出alert提示框,内容自拟
(2)菜单选项二、提示用户是否离开本页面。
(3)菜单选项三、跳转至百度搜索【页面中选中的内容】
(4)菜单选项四、弹出提示框,用户【在提示框中输入内容】然后跳转至百度进行搜索
</pre>
<ul>
    <li>弹出alert提示框</li>
    <li>离开本页面</li>
    <li>在百度搜索选中内容</li>
    <li>输入内容并跳转百度搜索</li>
</ul>
<textarea cols="30" rows="10"></textarea>
<script>
    //系统右键菜单禁止事件【contextmenu】
    document.oncontextmenu = function (eve) {
        return false;  //return false表示事件禁用
    };
    //获取ul
    var ul = document.querySelector("ul");
    //当鼠标放开时
    document.onmouseup = function (eve) {
        //eve.button能够判断鼠标用的是哪个按钮
        // console.log(eve.button);
        //当右键点击页面时,右键菜单显示
        if (eve.button==2){
            ul.style.display='block';
            //位置为鼠标位置
            ul.style.left = eve.clientX + 'px';
            ul.style.top = eve.clientY + 'px';
        //点击其他位置隐藏
        }else {
            ul.style.display='none';
        }
    };
    //事件委托,分别点击每个li,发生不同事件
    ul.onclick = function (eve) {
        if (eve.target.innerHTML =='弹出alert提示框'){
            alert('提示框');
        }else if(eve.target.innerHTML =='离开本页面'){
            if (confirm('是否离开本页面')){
                close();
            }
        }else if(eve.target.innerHTML =='在百度搜索选中内容'){
            //获取选中内容,并转成字符串
            var result = document.getSelection().toString();
            console.log(result);
            // window.open('https://www.baidu.com/s?wd='+result);
        }
    }
</script>
</body>
</html>

图片.png

老师,这里是不是应该打印的是选中的内容?

图片.png图片.png

我这里点击后,为什么显示的是个空字符串呢?正常不是应该输出的是‘跳转至百度’这几个字吗?是代码哪里有问题吗?

WEB前端全系列/第二阶段:JavaScript编程模块/面向对象编程 29877楼
Python 全系列/第九阶段:Flask百战电商后台系统/Flask百战电商后台项目 29880楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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