Javascript selection的兼容性寫法介紹
更新時間:2013年12月20日 17:12:46 作者:
本文為大家講解下Javascript selection的兼容性寫法,感興趣的朋友可以參考下
復制代碼 代碼如下:
function getSelectedText() { //this function code is borrowed from: http://www.codetoad.com/javascript_get_selected_text.asp
var txt = "";
if (window.getSelection) {
txt = window.getSelection();
} else if (window.document.getSelection) {
txt = window.document.getSelection();
} else if (window.document.selection) {
txt = window.document.selection.createRange().text;
}
return txt;
}
相關文章
在JS中操作時間之getUTCMilliseconds()方法的使用
這篇文章主要介紹了在JavaScript中操作時間之getUTCMilliseconds()方法的使用,是JavaScript入門學習中的基礎知識,需要的朋友可以參考下2015-06-06
ECMAScript 5嚴格模式(Strict Mode)介紹
這篇文章主要介紹了ECMAScript 5嚴格模式(Strict Mode)介紹,本文講解了如何啟用嚴格模式、啟用嚴格模式后對變量和屬性、函數、with語句的影響,需要的朋友可以參考下2015-03-03
使用Java實現(xiàn)簡單的server/client回顯功能的方法介紹
本篇文章介紹了,使用Java實現(xiàn)簡單的server/client回顯功能的方法。需要的朋友參考下2013-05-05

