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

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

    If you insist on 'http://' being the the default value, add the "value" attribute to the input tag:

    
    

    Allow users to remove it if they wish, yet validate when the form is sent. (jQuery's validation plugin)

提交回复
热议问题