有一些文本輸入。輸入聚焦時(第一次單擊輸入),必須選擇此輸入中的所有文本;第二次單擊輸入時,必須選擇特定的單詞。我嘗試實現與Chrome(版本74.0.3729.131(正式版本)(64位))中的URL欄相同的功能。您可以在此處查看輸入的當前行為:https : //jsfiddle.net/deaamod1s/rh5mw0e4/23/我看到的唯一解決方案是檢查是否雙擊輸入,然后如果未雙擊輸入,則執(zhí)行此操作 input.select()input.onfocus = function(e) { let hasValueWhenGotFocused = false; if (input.value) { hasValueWhenGotFocused = true; } setTimeout(() => { if (hasValueWhenGotFocused && this.className.indexOf("doubleclicked") == -1) { this.select(); } else { this.classList.remove("doubleclicked"); } },400); } input.ondblclick = function(e){ this.classList.add('doubleclicked'); }
input.select()后如何突出顯示輸入中的雙擊單詞
冉冉說
2021-05-16 10:02:45