Html 商品计算表单设计
1.功能描述:
- 输入商品的购买数量,单击购买按键,计算出购买金额,
- 提交按键表单提交
- 后续功能后面更新
2. 界面:
3. 代码
.html
<body>
<div id="wrapper">
<h1>商品表单</h1>
<table id="keywords" cellspacing="1" cellpadding="0">
<thead>
<tr>
<th><span>商品</span></th>
<th><span>价格</span></th>
<th><span>数量</span></th>
<th><span>购买数量</span></th>
<th><span>购买</span></th>
<th><span>购买金额</span></th>
</tr>
</thead>
<tbody>
<tr>
<td class="lalign"> tshirts</td>
<td>6,000</td>
<td>110</td>
<td><input type='' id= 'id0' value=0></td>
<td><button onclick="buy0()">购买</button></td>
<td><input id='pay0' value=0></td>
</tr>
<tr>
<td class="lalign">workspace photos</td>
<td>2,200</td>
<td>500</td>
<td><input type='' id= 'id1' value=0></td>
<td><button onclick="buy1()">购买</button></td>
<td><input id='pay1' value=0></td>
</tr>
<tr>
<td class="lalign">arrested development quotes</td>
<td>13,500</td>
<td>900</td>
<td><input type='' id= 'id2' value=0></td>
<td><button onclick="buy2()">购买</button></td>
<td><input id='pay2' value=0></td>
</tr>
<tr>
<td class="lalign">popular web series</td>
<td>8,700</td>
<td>350</td>
<td><input type='' id= 'id3' value=0></td>
<td><button onclick="buy3()">购买</button></td>
<td><input id='pay3' value=0></td>
</tr>
<tr>
<td class="lalign">2013 webapps</td>
<td>9,900</td>
<td>460</td>
<td><input type='' id= 'id4' value=0></td>
<td><button onclick="buy4()">购买</button></td>
<td><input id='pay4' value=0></td>
</tr>
<tr>
<td class="lalign">ring bananaphone</td>
<td>10,500</td>
<td>748</td>
<td><input type='' id= 'id5' value=0></td>
<td><button onclick="buy5()">购买</button></td>
<td><input id='pay5' value=0></td>
</tr>
</tbody>
</table>
<button id='button' > 提交</button>
</div>
</body>
.css
@import url('https://fonts.googleapis.com/css?family=Amarante');
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
outline: none;
-webkit-font-smoothing: antialiased;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html { overflow-y: scroll; }
body {
background: #eee url('https://i.imgur.com/eeQeRmk.png'); /* https://subtlepatterns.com/weave/ */
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 62.5%;
line-height: 1;
color: #585858;
padding: 22px 10px;
padding-bottom: 55px;
}
::selection { background: #5f74a0; color: #fff; }
::-moz-selection { background: #5f74a0; color: #fff; }
::-webkit-selection { background: #5f74a0; color: #fff; }
br { display: block; line-height: 1.6em; }
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block; }
ol, ul { list-style: none; }
input, textarea {
-webkit-font-smoothing: antialiased;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
outline: none;
}
blockquote, q { quotes: none; }
blockquote:before, blockquote:after, q:before, q:after { content: ''; content: none; }
strong, b { font-weight: bold; }
table { border-collapse: collapse; border-spacing: 0; }
img { border: 0; max-width: 100%; }
h1 {
font-family: 'Amarante', Tahoma, sans-serif;
font-weight: bold;
font-size: 3.6em;
line-height: 1.7em;
margin-bottom: 10px;
text-align: center;
}
/** page structure **/
#wrapper {
display: block;
width: 1000px;
background: #fff;
margin: 0 auto;
padding: 10px 17px;
-webkit-box-shadow: 2px 2px 3px -1px rgba(0,0,0,0.35);
}
#keywords {
margin: 0 auto;
font-size: 1.2em;
margin-bottom: 15px;
}
#keywords thead {
cursor: pointer;
background: #c9dff0;
}
#keywords thead tr th {
font-weight: bold;
padding: 12px 30px;
padding-left: 42px;
}
#keywords thead tr th span {
padding-right: 20px;
background-repeat: no-repeat;
background-position: 100% 100%;
}
#keywords thead tr th.headerSortUp, #keywords thead tr th.headerSortDown {
background: #acc8dd;
}
#keywords thead tr th.headerSortUp span {
background-image: url('https://i.imgur.com/SP99ZPJ.png');
}
#keywords thead tr th.headerSortDown span {
background-image: url('https://i.imgur.com/RkA9MBo.png');
}
#keywords tbody tr {
color: #555;
}
#keywords tbody tr td {
text-align: center;
padding: 15px 10px;
}
#keywords tbody tr td.lalign {
text-align: left;
}
#button{
padding: 7px 40px;
margin-left: 755px;
}
.js
function buy0(){
element=document.getElementById('pay0');
element1=document.getElementById('id0');
if(document.getElementById('id0').value<110){
element.value = element1.value*6000;
}else{
alert('没有那么多商品');
element1.value =0;
}
};
function buy1(){
element=document.getElementById('pay1');
element1=document.getElementById('id1');
if(document.getElementById('id1').value<500){
element.value = element1.value*2200;
}else{
alert('没有那么多商品');
element1.value =0;
}
};
function buy2(){
element=document.getElementById('pay2');
element1=document.getElementById('id2');
if(document.getElementById('id2').value<900){
element.value = element1.value*13500;
}else{
alert('没有那么多商品');
element1.value =0;
}
};
function buy3(){
element=document.getElementById('pay3');
element1=document.getElementById('id3');
if(document.getElementById('id3').value<350){
element.value = element1.value*8700;
}else{
alert('没有那么多商品');
element1.value =0;
}
};
function buy4(){
element=document.getElementById('pay4');
element1=document.getElementById('id4');
if(document.getElementById('id4').value<460){
element.value = element1.value*9900;
}else{
alert('没有那么多商品');
element1.value =0;
}
};
function buy5(){
element=document.getElementById('pay5');
element1=document.getElementById('id5');
if(document.getElementById('id5').value<748){
element.value = element1.value*10500;
}else{
alert('没有那么多商品');
element1.value =0;
}
};
著名:小伙伴可以到这里演示一下https://codepen.io/trending