我正在使用 push 方法向现有数组 (st[]) 添加新值。添加一个新值是可行的,但是数组中的所有值都将获得最后添加的元素的值。
if(!window.WordCatcher){
WordCatcher = {};
}
WordCatcher.selector = {};
WordCatcher.selector.getSelected = function(){
var t = '';
if(window.getSelection) {t = window.getSelection();}
else if(document.getSelection) {t = document.getSelection();}
else if(document.selection) {t = document.selection.createRange().text;}
return t;
}
st = new Array();
WordCatcher.selector.dblclick = function() {
st.push(WordCatcher.selector.getSelected());
console.log(st);
}
在 jQuery 中调用函数:
$(document).bind("dblclick", WordCatcher.selector.dblclick);
示例:如果我双击第一个“Die”,第二个“Smart”,第三个“TV”,我将在 firebug 中得到以下日志:
[Die { constructor=Selection, focusNode=textNode, anchorNode=textNode, mehr...}] [Smart {constructor=Selection, focusNode=textNode, anchorNode=textNode, mehr...}, Smart {constructor=Selection, focusNode=textNode, anchorNode=textNode, mehr...}] [TV { constructor=Selection, focusNode=textNode, anchorNode=textNode, mehr...}, TV {constructor=Selection, focusNode=textNode, anchorNode=textNode, mehr...}, TV {constructor=Selection, focusNode=textNode, anchorNode=textNode, mehr...}]
也许有人知道我在做什么工作。
最好的问候,安迪