0
我的JavaScript不太好,所以我只能希望這是有道理的。我想創建一個DOMSelection對象,如從如何從特定節點創建DOMSelection對象?
返回的那個對象。因此可以說,我有這樣的jQuery監聽設置是這樣的:
$("#target").click(function() {
var sel = createSelectionFromNode(this);
});
我只想範圍是從節點到節點的終結的開始。是否有捷徑可尋?我專門尋找WebKit兼容解決方案,可以忽略IE。謝謝你的幫助。
的例子,點擊文本應該返回像DOMSelection對象:
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 2012-04-28 21:25:44
上面添加的示例 – browep 2012-04-28 21:41:03