jkd112233 2023-03-12 15:45 采纳率: 85.4%
浏览 628
已结题

有关于js部分的问题,需要完成一个订单确认的页面

有关于js部分的问题,需要完成一个订单确认的页面,框架如下:

<html>
<head>
<style>
body{margin:0px;}
#orderForm, #confirmForm{postion:absolute; width:280px; height:440px; margin:5px; display:inline-block; padding:5px;}
#orderForm{background-color:#abc; display:inline-block;}
#confirmForm{position:absolute; background-color:#def; }
#bttn{position:absolute; bottom:15px;}
#msg{color:F23; font-weight:bold;}
</style>
</head>

<body>
<div id="orderForm">
<h3>Stationery Order</h3>
<h5>Please complete the form</h5>
<p><input type="text" id="firstName"  placeholder="Enter Your First Name" /></p>
<p><input type="text" id="familyName" placeholder="Enter Your Famiy Name" /></p>
<p>Select Title</p>
<input type="radio" name="citizen" value="cn" checked />Chinese Style
<input type="radio" name="citizen" value="wn" />Western Style
<p>
<input type="radio" name="titles" value="Prof." />Prof.
<input type="radio" name="titles" value="Dr."   />Dr.
<input type="radio" name="titles" value="Mr."   />Mr.
<input type="radio" name="titles" value="Ms."   />Ms.</p>

<input type="checkbox" id="otherChk" name="other" />other
<input type="text" id="otherTitle" placeholder="Enter Your Title" />
<br><br>
<input type="checkbox" id="pen"     name="orders" value="Pen" />Pen
<input type="checkbox" id="ruler"     name="orders" value="Ruler" />Ruler<br>
<input type="checkbox" id="notepad" name="orders" value="Notepad" />Notepad
<input type="checkbox" id="clips"     name="orders" value="Paper Clips" />Paper Clips<br>
<input type="checkbox" id="stapler" name="orders" value="Stapler" />Stapler
<input type="checkbox" id="paper"     name="orders" value="Paper(A4" />Paper(A4)

<p><button id="orderBtn" onclick="ord()">Order</button></p>
<p id="msg"></p>
<div id="confirmForm"> <div id="printTitle"></div> <div id="printOrder"></div> <p id ="bttn"> <button id="confirmBtn" disabled >Confirm Order</button> <button id="cancelBtn" >Cancel Order</button></p>
<script> </script> </body> </html>

这是要求:

img


下面分别是都没有输入值都有输入值的结果展现:

img

img

  • 写回答

6条回答 默认 最新

  • CSDN专家-showbo 2023-03-12 21:10
    关注
    获得7.50元问题酬金
    
    <html>
    <head>
        <style>
            body {
                margin: 0px;
            }
    
            #orderForm, #confirmForm {
                position: absolute;
                width: 280px;
                height: 440px;
                margin: 5px;
                display: inline-block;
                padding: 5px;
            }
    
            #orderForm {
                background-color: #abc;
                display: inline-block;
            }
    
            #confirmForm {
                position: absolute;
                background-color: #def;
                left:280px
            }
    
            #bttn {
                position: absolute;
                bottom: 15px;
            }
    
            #msg {
                color: #F23;
                font-weight: bold;
            }
        </style>
    </head>
    
    <body>
        <div id="orderForm">
            <h3>Stationery Order</h3>
            <h5>Please complete the form</h5>
            <p><input type="text" id="firstName" placeholder="Enter Your First Name" /></p>
            <p><input type="text" id="familyName" placeholder="Enter Your Famiy Name" /></p>
            <p>Select Title</p>
            <input type="radio" name="citizen" value="cn" checked />Chinese Style
            <input type="radio" name="citizen" value="wn" />Western Style
            <p>
                <input type="radio" name="titles" value="Prof." />Prof.
                <input type="radio" name="titles" value="Dr." />Dr.
                <input type="radio" name="titles" value="Mr." />Mr.
                <input type="radio" name="titles" value="Ms." />Ms.
            </p>
    
            <input type="checkbox" id="otherChk" name="other" />other
            <input type="text" id="otherTitle" placeholder="Enter Your Title" />
            <br><br>
            <input type="checkbox" id="pen" name="orders" value="Pen" />Pen
            <input type="checkbox" id="ruler" name="orders" value="Ruler" />Ruler<br>
            <input type="checkbox" id="notepad" name="orders" value="Notepad" />Notepad
            <input type="checkbox" id="clips" name="orders" value="Paper Clips" />Paper Clips<br>
            <input type="checkbox" id="stapler" name="orders" value="Stapler" />Stapler
            <input type="checkbox" id="paper" name="orders" value="Paper(A4" />Paper(A4)
    
            <p><button id="orderBtn" onclick="ord()">Order</button></p>
        </div>
        <div id="confirmForm">
            <p id="msg"></p>
    
    
            <div id="printTitle"></div>
            <div id="printOrder"></div>
            <p id="bttn">
                <button id="confirmBtn" disabled>Confirm Order</button>
                <button id="cancelBtn">Cancel Order</button>
            </p>
        </div>
    
    
    
        <script>
            function ord() {
                cancelBtn.onclick();//调用取消按钮重置过状态
                var errors = []
                if (firstName.value == '' || familyName.value == '') {
                    errors.push('Please enter all your names');
                }
                var title = Array.from(document.getElementsByName('titles')).find(i => i.checked);
                if (!title && !otherChk.checked) errors.push('Select a title or click the check box');
                else {
                    if (otherChk.checked) title = otherTitle.value;
                    else title = title.value;
                }
    
                if (title) title += ' ';
    
                var orders = Array.from(document.getElementsByName('orders')).filter(i => i.checked);
                if (!orders.length) errors.push('Click at least one check box');
                if (errors.length) {
                    msg.innerHTML = '<h1>Confirm Order</h1><ul>' + errors.map(i => `<li>${i}</li>`).join('') + '<ul>'
                    return
                }
                var cn = Array.from(document.getElementsByName('citizen')).find(i => i.checked).value == 'cn';
                var names = [familyName.value, firstName.value];//默认中文显示样式
                if (!cn) names = names.reverse();//英文样式反转数组
               
                printTitle.innerHTML = '<h1>Confirm Order</h1>';
                confirmBtn.disabled = false;
                printOrder.innerHTML = 'Please confirm the order<br><br>'
                    + 'Dear ' + title + names.join(' ') + '<br>thank you for your order of:'
                    + '<ol>' + orders.map(i => `<li>${i.value}</li>`).join('') + '</ol>';
            }
    
            //取消按钮事件
            cancelBtn.onclick = function () {
                confirmBtn.disabled = true;
                printTitle.innerHTML = printOrder.innerHTML = msg.innerHTML = '';
            }
            //确认按钮事件
            confirmBtn.onclick = function () {
               // printTitle.innerHTML  = msg.innerHTML = '';
               // printOrder.innerHTML = 'We are sending your order now ' + firstName.value
                alert('We are sending your order now ' + firstName.value)
            }
        </script>
    </body>
    </html>
    
    
    评论 编辑记录
    1人已打赏

报告相同问题?

问题事件

  • 系统已结题 3月20日
  • 赞助了问题酬金15元 3月12日
  • 创建了问题 3月12日

悬赏问题

  • ¥15 CCF-CSP 2023 第三题 解压缩(50%)
  • ¥30 comfyui openpose报错
  • ¥20 Wpf Datarid单元格闪烁效果的实现
  • ¥15 图像分割、图像边缘提取
  • ¥15 sqlserver执行存储过程报错
  • ¥100 nuxt、uniapp、ruoyi-vue 相关发布问题
  • ¥15 浮窗和全屏应用同时存在,全屏应用输入法无法弹出
  • ¥100 matlab2009 32位一直初始化
  • ¥15 Expected type 'str | PathLike[str]…… bytes' instead
  • ¥15 三极管电路求解,已知电阻电压和三级关放大倍数