在jquery/javascript中的inputbox中的特定项后设置焦点
假设我有一个输入框,看起来像这样:在jquery/javascript中的inputbox中的特定项后设置焦点,javascript,jquery,html,Javascript,Jquery,Html,假设我有一个输入框,看起来像这样: <input id="fuzzyname" value="" placeholder="&Fuzzybear"> 啊,setSelectionRange就是我要找的。非常感谢。 $("#fuzzyname").focus(function () { var value = $(this).attr("placeholder"); var symbol = "&"; var cursorIn
<input id="fuzzyname" value="" placeholder="&Fuzzybear">
啊,setSelectionRange就是我要找的。非常感谢。
$("#fuzzyname").focus(function () {
var value = $(this).attr("placeholder");
var symbol = "&";
var cursorIndex = value.indexOf(symbol);
//This is where I want to output the value into the inputbox with the cursor after cursorIndex
});
var cursorIndex = value.indexOf(symbol) + 1;
$(this).val(value);
this.setSelectionRange(cursorIndex, cursorIndex);