h5开发小细节

1.        输入框去除两边空格     

$('#id名').val().trim()

2.        配置样式时,前面加上大div标签,避免全局污染

#big span

3.        输入框常用配置样式

input{

            width: 200px;

            height:20px;

            padding: 4px 0;

            outline: none;

            font-size: 14px;

            text-indent: 10px;

            color: #333;

            box-shadow: none;

        }

4.单选框

<!DOCTYPE html>

<html lang="en">

        <head>

        <meta charset="UTF-8">

        <title>HTML5</title>

        <style>

                

                 #big .checkBox{

                            font-size: 14px;

                 }

        </style>

        </head>

        <body>
               <div id="big" >

                        <div style="padding: 5px 0">

                                <div class="radioDiv">

                                        <span class="mandatory">申请等级:</span>

                                        <input type="radio" value="1"> <p>你</p>

                                        <input type="radio" value="2" > <p>我</p>

                                        <input type="radio" value="3" > <p>他</p>

                        </div>

                    </div>

                </div>

                <script  type="text/javascript">

                        

                        // 单选框

                        let radioValue = '';

                        $(".radioDiv input[type='radio']").click(function(){

                            //1.先移除之前元素的checked

                            $(".radioDiv input[type='radio']:checked").removeAttr("checked");

           

                            //2.给当前点击的单选框加checked

                            $(this).attr("checked","true")

                            radioValue = $(".radioDiv input[type='radio']:checked").val();

                         })

                </script>

        </body>

</html>

5.表单ajax提交

#big .btn{

            color: aliceblue;

            background-color: #3598ff;

            width: 200px;

            height: 35px;

            border-radius: 4px;

            border-style: none;

            font-size: 14px;

        }

          

                <div>

                        <span>姓名:</span>

                        <input type="text" id="name" value="">

                </div>

                <div>

                        <span>密码:</span>

                        <input type="number" id="password" value="" >

                 </div>

 

                <div>

                        <button class="btn">提交申请</button>

                 </div>

$("button").on('click', function(){

            const name = $('#name').val().trim();

            const password = $('#password').val().trim() || '';

            const disabled = !name || !password

            //const disabled = !name || !password || !radioValue                //radioValue是上面提到的

            if(disabled){

                alert('必填项,请填写完整');

            }else{

                const pram = {

                    content: {

                        name,

                        password,

                         radioValue,

                    }

                };

                $.ajax({

                    type : "POST",  //提交方式  

                    url : "",//路径  

                    data : pram, //数据,这里使用的是Json格式进行传输  

                    success : function(result) {//返回数据根据结果进行相应的处理  

                        alert(result.description);

                        $("#name").val("");

                        $("#password").val("");

                        //$(".radioDiv input[type='radio']:checked").removeAttr("checked");

                    },

                    complete: function() {

                        console.log();

                    }

                });

               

            }

        });

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值