How can I add an unremovable prefix to an HTML input field?

前端 未结 16 1412
猫巷女王i
猫巷女王i 2020-12-13 04:23

Using jQuery, how can I add a default value of http:// into an input field that can’t be removed, but that still allows you to type a URL after it?

Defa

16条回答
  •  情话喂你
    2020-12-13 04:44

    This is for the textbox, if user forgot to put http:// then it will add otherwise it won't.

    if (this.value.length > 7) {
    if(this.value.substring(0, 7)== "http://"  || this.value.substring(0, 
    8)== "https://"){
        this.value = this.value;
        }
        else{
                this.value = "http://" + this.value;
        }
    

提交回复
热议问题