任何人都可以提出一個插件可以處理文本區域(跨瀏覽器)的文本選擇?插件處理選擇?
我正在尋找一個插件,它能夠:
- 獲取當前選擇
- 替換當前選擇
- 選擇範圍
(IE使用createTextRange
而其他瀏覽器使用setSelectionRange
。應該有一個可以做以上的插件,這樣我就不必重新發明輪子了。)
任何人都可以提出一個插件可以處理文本區域(跨瀏覽器)的文本選擇?插件處理選擇?
我正在尋找一個插件,它能夠:
(IE使用createTextRange
而其他瀏覽器使用setSelectionRange
。應該有一個可以做以上的插件,這樣我就不必重新發明輪子了。)
jQuery的Fieldselection: https://github.com/localhost/jquery-fieldselection
參見: https://github.com/localhost/jquery-fieldselection/blob/master/jquery-fieldselection.js
指定者: getSelection,replaceSelection
沒有實現: currentSelection
瘦長: 指定者: getSelection,ReplaceSelection,CurrentSelection
(注意:不是一個jQuery插件,可廣泛適用依然)
跨瀏覽器的JavaScript範圍和選擇庫。它提供了一個簡單的基於標準的API,用於在所有主流瀏覽器中執行常見的DOM範圍和選擇任務,從而將Internet Explorer和符合DOM的瀏覽器之間的這種功能的截然不同的實現抽象出來。
似乎實現你想要什麼,對於演示的看到: http://rangy.googlecode.com/svn/trunk/demos/core.html
http://code.google.com/p/rangy/
參見:Jquery: selectionStart for non textarea elements
Rangyinputs 一個jQuery插件,提供了類似的功能瘦長,除了輸入而不是仲裁DOM元素。
一個小型的跨瀏覽器JavaScript庫,用於獲取和操作HTML元素中的選擇。
演示:http://rangyinputs.googlecode.com/svn/trunk/demos/textinputs_jquery.html
以下插件可以幫助你http://www.examplet.buss.hk/jquery/caret.php
這是也有幫助我
我創造了我自己。只有2.6kb的未壓縮:http://blog.gauffin.org/2012/02/a-javascript-selection-script/
//jQuery is not required but supported.
var selection = new textSelector($('#mytextarea'));
selection.replace('New text');
// you can change selection:
selection.select(1,10); // select char 1 to 10
// get selection
console.log("Start char: " + selection.get().start);
// check if anything is selected
selection.isSelected();
// get the text
var text = selection.text();
它可在github上:https://raw.github.com/jgauffin/griffin.editor/master/Source/textselector.js
我試過很多在座的各環節,以及其他從jQuery插件庫,和他們沒有工作,我想要的方式。
但有這一項,這裏不mentionned,那真是有趣:
http://madapaja.github.io/jquery.selection/
希望能對大家有所幫助! :)
http://codepen.io/mattsich/pen/MKvmxQ對於我構建的iOS樣式選擇。最後只是這個:
$(document).ready(function(){
$(".full-text").selectBars('.full-text', 'ipsum', function(){
$('.selected-text p').text($('.full-text').attr('data-selected'));
});
});
也許你可以更具體一些你會想象這樣的插件會有什麼特點? – Arend 2012-02-20 13:43:07
不是一個完全的插件,但看看[這個問題](http://stackoverflow.com/q/985272/552438)。 – 2012-02-20 13:47:41
@Arend:閱讀我的更新。 – jgauffin 2012-02-20 13:48:03