JS focuses the cursor on the implementation code at the end of the text

  • 2020-03-30 02:29:06
  • OfStack

 
<span style="font-family:Times New Roman;font-size:18px;"><script type="text/javascript"> 
//Focus the cursor at the end of the text
function cursorEnd(){ 
var e = event.srcElement; 
var r = e.createTextRange(); 
r.moveStart('character',e.value.length); 
r.collapse(true); 
r.select(); 
} 
</script> 
<input type=text name="test" value="test" onfocus="cursorEnd()"></span> 

Related articles: