私のjavascriptはそれほど良くありませんので、私はこれが意味をなされることを願っています。特定のノードからDOMSelectionオブジェクトを作成するにはどうすればよいですか?
window.getSelection()
のDOMSelectionオブジェクトをノードのonclickから作成したいとします。
$("#target").click(function() {
var sel = createSelectionFromNode(this);
});
私は唯一の範囲は、ノードの最後にノードの先頭からになりたい:私はこのように、このjQueryのリスナーを設定していると言うことができます。これを行う簡単な方法はありますか?私は特にWebKit互換のソリューションを探しています。IEを無視しても問題ありません。助けてくれてありがとう。
例:、テキストをクリックすると、DOMSelectionオブジェクトを返す必要がありますように例のhttp://jsfiddle.net/8j4Bf/
:
DOMSelection
anchorNode: Text
attributes: null
baseURI: "http://jsfiddle.net/8j4Bf/"
childNodes: NodeList[0]
data: "HTML"
firstChild: null
lastChild: null
length: 4
localName: null
namespaceURI: null
nextSibling: null
nodeName: "#text"
nodeType: 3
nodeValue: "HTML"
ownerDocument: HTMLDocument
parentElement: HTMLSpanElement
parentNode: HTMLSpanElement
prefix: null
previousSibling: null
textContent: "HTML"
wholeText: "HTML"
__proto__: Text
anchorOffset: 0
baseNode: Text
baseOffset: 0
extentNode: Text
extentOffset: 0
focusNode: Text
attributes: null
baseURI: "http://jsfiddle.net/8j4Bf/"
childNodes: NodeList[0]
data: "HTML"
firstChild: null
lastChild: null
length: 4
localName: null
namespaceURI: null
nextSibling: null
nodeName: "#text"
nodeType: 3
nodeValue: "HTML"
ownerDocument: HTMLDocument
parentElement: HTMLSpanElement
parentNode: HTMLSpanElement
prefix: null
previousSibling: null
textContent: "HTML"
wholeText: "HTML"
__proto__: Text
focusOffset: 0
isCollapsed: true
rangeCount: 1
type: "Caret"
あなたが例を与えることができますか? – gdoron
上記の例が追加されました – browep