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

前端 未结 16 1396
猫巷女王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:49

    Not so clean but it doesn't let users remove your prefix

      
    
    //prefix
    $(document).on('keyup','#membership_num',function(){
      var original = $('#membership_num').val().split('');
      original[0] = "0";
      original[1] = "2";
      original[2] = "0";
      original[3] = "1";
      $('#membership_num').val(original.join(''));
    });
    

提交回复
热议问题