| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>新增商品</title>
- <script src="../js/jquery-2.1.4.js"></script>
- <style>
- /* 全局样式重置 - 统一跨浏览器样式,消除默认边距 */
- * {
- margin: 0;
- padding: 0;
- box-sizing: border-box;
- font-family: "Microsoft Yahei", sans-serif;
- }
- /* 页面背景 - 浅灰背景提升层次感,flex让表单垂直+水平居中 */
- body {
- background-color: #f5f5f5;
- min-height: 100vh;
- display: flex;
- justify-content: center;
- align-items: center;
- padding: 20px;
- }
- /* 表单容器 - 白色卡片、圆角、阴影,和之前页面风格统一 */
- form {
- background-color: #ffffff;
- padding: 40px 35px;
- border-radius: 8px;
- box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
- width: 100%;
- max-width: 450px;
- }
- /* 表单标题 - 居中显示,和容器匹配,增加底部间距 */
- form h2 {
- text-align: center;
- color: #333333;
- font-size: 24px;
- font-weight: 600;
- margin-bottom: 30px;
- }
- /* 标签样式 - 固定宽度,右对齐,统一文字颜色和大小 */
- form label {
- display: inline-block;
- width: 90px;
- text-align: right;
- color: #666666;
- font-size: 16px;
- margin-right: 15px;
- }
- /* 输入框统一样式 - 文本框/数字框共用,美化边框和内边距 */
- input[type="text"],
- input[type="number"] {
- width: calc(100% - 110px);
- padding: 12px 15px;
- margin: 8px 0 18px 0;
- border: 1px solid #e5e6eb;
- border-radius: 4px;
- font-size: 16px;
- color: #333;
- transition: all 0.3s ease;
- outline: none;
- }
- /* 输入框聚焦效果 - 蓝色边框+轻阴影,提升交互反馈 */
- input[type="text"]:focus,
- input[type="number"]:focus {
- border-color: #409eff;
- box-shadow: 0 0 6px rgba(64, 158, 255, 0.2);
- }
- /* 数字框去除默认上下箭头 - 美化外观,不影响功能 */
- input[type="number"]::-webkit-inner-spin-button,
- input[type="number"]::-webkit-outer-spin-button {
- -webkit-appearance: none;
- margin: 0;
- }
- /* 保存按钮样式 - 通栏显示,美化配色和交互 */
- input[type="button"] {
- width: 100%;
- padding: 12px 0;
- border: none;
- border-radius: 4px;
- background-color: #409eff;
- color: #ffffff;
- font-size: 16px;
- font-weight: 500;
- cursor: pointer;
- transition: background-color 0.3s ease;
- margin-top: 10px;
- }
- /* 按钮hover/点击效果 - 加深颜色,提升交互体验 */
- input[type="button"]:hover {
- background-color: #337ecc;
- }
- input[type="button"]:active {
- background-color: #266fc8;
- }
- </style>
- </head>
- <body>
- <form action="#">
- <!-- 新增表单标题,和整体风格匹配 -->
- <h2>新增商品</h2>
- <label for="id">商品ID:</label>
- <input type="text" name="id" id="id"><br>
- <label for="productName">商品名称:</label>
- <input type="text" name="productName" id="productName"><br>
- <label for="stocket">商品库存:</label>
- <input type="number" name="stocket" id="stocket"><br>
- <label for="title">商品标题:</label>
- <input type="text" name="title" id="title"><br>
- <input type="button" value="保存" onclick="add()">
- </form>
- <script>
- function add(){
- var id = document.getElementById("id").value
- var productName = document.getElementById("productName").value
- var stocket = document.getElementById("stocket").value
- var title = document.getElementById("title").value
- // 简单非空校验 - 新增优化,避免空参数提交
- if(!id || !productName || !stocket || !title){
- alert("请填写完整的商品信息!");
- return;
- }
- $.post("http://c46a5489.natappfree.cc/product/add",{
- id:id,
- productName:productName,
- title:title,
- stocket:stocket
- },function(result){
- if(result.success){
- location.href = "/js-demo-day02/js-demo-day02/demo/product.html"
- }else{
- alert("添加失败:" + (result.msg || "未知错误"));
- }
- },"json") // 新增指定返回格式为json,避免解析错误
- .fail(function(){ // 新增请求失败回调,提示网络错误
- alert("网络错误,添加请求发送失败!");
- });
- }
- </script>
- </body>
- </html>
|