html标签属性

oninput实时判断input框里面的值是不是符合要求

<style>
    span{
        display: none;
        color: red;
        margin:0 auto 15px;
        width: 300px;
        }
</style>
<input id="mobile" name="mobile" required="required"  type="number" placeholder="请输入账号"  oninput="check()" />
<script>
<span class="isphone">请输入正确的11位手机号码</span>
// 判断手机号是不是11位
    function check() {
        var mobile = $("#mobile").val();
        if(mobile.length>11){
            mobile=mobile.slice(0,11)
        }
        if(mobile.length==11){
            $(".code_message").attr("onclick", "sendMessage()");
            $(".code_message").css("background", "#5E7CDC");
            $('.isphone').css('display','none')
        }else{
            $(".code_message").removeAttr("onclick")
            $('.isphone').css('display','block')
        }
    }
</script>

在form表单中使用button时,使用input type=button

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容