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


<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>03.ajax的post的参数传递</title>

</head>

<body>

    <h1>03.ajax的post的参数传递</h1>

    name:<input type="text" id="name"><br/>

    password:<input type="text" id='name'><br/>

    <input type="button" value="获取参数" onclick="submitForm()">

    <input type="button" value="获取参数-post" onclick="submitForm2()">

    <script>

        function submitForm(){

            var name = document.getElementById('name').value

            var pwd = document.getElementById('pwd').value

            url='http://httpbin.org/get'

            params='name='+name+'&pwd'+pwd

            var xhr=new XMLHttpRequest()

            xhr,open('post',url)

            xhr.setRequestHeader('Content-Type','application/x_wwww-form-urlencoded')

            xhr.send(params)

            xhr.onload = function(){

                console.log(xhr.responseText)

            }            

        }


            function submitForm2(){

                var name = document.getElementById('name').value

                var pwd = document.getElementById('pwd').value

                url='http://httpbin.org/post'

                params={'name':name,'pwd':pwd}

                var xhr=new XMLHttpRequest()

                xhr,open('post',url)

                xhr.setRequestHeader('Content-Type','application/json')

                xhr.send(params)

                xhr.onload = function(){

                    console.log(xhr.responseText)

                }            

            }

        </script>

</body>

</html>



报错原因:

03.Ajax的post的参数传递.html:31 Uncaught TypeError: Cannot read properties of null (reading 'value')

    at submitForm2 (03.Ajax的post的参数传递.html:31)

    at HTMLInputElement.onclick (03.Ajax的post的参数传递.html:12)

submitForm2 @ 03.Ajax的post的参数传递.html:31

onclick @ 03.Ajax的post的参数传递.html:12


Python 全系列/第七阶段:网页编程基础/Ajax 15106楼
Python 全系列/第九阶段:Flask百战电商后台系统/Flask百战电商后台项目 15108楼
软件测试 全系列/预科阶段:测试环境和操作系统/VMWare的使用和Windows的安装 15109楼
JAVA 全系列/第十三阶段:分布式文件存储与数据缓存/MongoDB 15110楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/常用类 15111楼
JAVA 全系列/第一阶段:JAVA 快速入门/飞机大战小项目训练 15112楼

<!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>

    <script>
        var arr = ['首页', '军事', '论坛', '视频'];
        //创建、设置ul元素
        var u = document.createElement('ul');
        var u_css = document.createAttribute('style');
        u_css.value = 'list-style:none;margin:0;padding:0';
        u.setAttributeNode(u_css)
        //创建li a元素 并设置元素
        for (var i = 0; i <= arr.length - 1; i++) {
            var li = document.createElement('li');
            var li_css = document.createAttribute('style');
            li_css.value = 'display:inine-block;widht:100px;height:30px;line-height=30px;background=skyblue;aligin=center';
            li.setAttributeNode(li_css);
            var a = document.createElement('a');
            var a_css = document.createAttribute('style');
            a_css.value = 'text-decoration: none;';
            a.innerHTML = arr[i];
            a.setAttributeNode(a_css);

            console.log(a.innerHTML);

            li.appendChild(a);
            u.appendChild(li);

        }
        document.body.appendChild(u);
    </script>
</body>

</html>

老师为啥我 li的css出不来

WEB前端全系列/第二阶段:JavaScript编程模块/DOM模型 15113楼
JAVA 全系列/第一阶段:JAVA 快速入门/飞机大战小项目训练 15114楼
JAVA 全系列/第九阶段:Spring Boot实战/Spring Boot 15116楼
JAVA 全系列/第三阶段:数据库编程/MySQL数据库 15117楼
JAVA 全系列/第十三阶段:分布式文件存储与数据缓存/MongoDB 15119楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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