jquery获取和设置textarea光标位置

奇迹之耀 / 2023-06-02 / 原文

var textarea=$("textarea[name=xxx]")

//获取光标位置

var index = textarea.prop("selectionStart");

//设置光标位置

textarea.prop("selectionStart", index);
textarea.prop("selectionEnd", index);