Html Put a fixed text on an input text

后端 未结 7 1341
梦毁少年i
梦毁少年i 2020-12-11 04:21

How can i put a default text in an input html element which user can\'t delete (fixed text on start of the input).

The second thing what i want that the cursor will b

7条回答
  •  执念已碎
    2020-12-11 04:34

    var requiredText = 'https://';
    $('#site').on('input', function() {
      if (String($(this).val()).indexOf(requiredText) == -1) {
        $(this).val(requiredText);
      }
    });
    
    

提交回复
热议问题