第一個腳本,當滑鼠移到input、textarea元素的文本框,自動聚焦,游標在文字末尾,移出input、textarea會自動失焦
另一個腳本,劃詞彈圖示欄
滑鼠從圖示欄移到文本框后,或者點擊圖示執行功能,比如復制,圖示欄自動消失后,滑鼠在文本框,會自動再次聚焦文本框,劃詞的文字會消失,游標在文字末尾
如何讓滑鼠從圖示欄,移回到文本框不再自動聚焦,保留劃詞文字
有一個思路,使用油猴子存盤本次滑鼠所在位置的元素,移到下一個元素判斷上一個元素是是img,就不自動聚焦,從input、textarea元素移到img元素清除失焦的計時
不知道如何存盤本次的元素,作為下一次的判斷
圖示欄元素e.target.localName ==='img'
劃詞彈圖示欄工具
//自動聚焦
document.addEventListener('mouseover', function (e) {
if (e.target.localName ==='input' || e.target.localName ==='textarea'){
e.target.focus();
var val = e.target.value; //store the value of the element
e.target.value = ''; //clear the value of the element
e.target.value = val; //set that value back.
}
});
//失焦
document.addEventListener('mouseout', function (e) {
var text = window.getSelection().toString().trim();
timer = setTimeout(function () {
e.target.blur();
}, 20)
if(text){
clearTimeout(timer);
}
},false);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/233727.html
標籤:JavaScript
