输入框清除按钮(自定义)

<input id="sjh" type="text" name="" oncopy="" required value="" class="ipt" placeholder="请输入手机号" onkeyup="Mobile2(this)" />
<span class="mui-icon mui-icon-closeempty input_clear"></span>

css:

span{

        display: none;position: absolute;right: 30px;top: 58px;border-radius: 50%;

}

js:

$(function(){
                $("#sjh").on("input propertychange",function(){
                    val = this.value.length;
                    if(val >= 1){
                        $(this).parent().children(".input_clear").show();
                    }else{
                        $(this).parent().children(".input_clear").hide();
                    }
                });
                $("#sjh").blur(function(){
                    if($(this).val()=='')
                    {
                        $(this).parent().children(".input_clear").hide();
                    }
                });
                $(".input_clear").click(function(){
                    $(this).parent().find('#sjh').val('');
                    $(this).hide();
                    $(".xiayibu button").removeClass('submit').addClass('active-btn').attr('disabled', true);
                });
            })

猜你喜欢

转载自blog.csdn.net/qq_40001322/article/details/81448340
今日推荐