【发布时间】:2012-08-08 00:45:03
【问题描述】:
我有一个功能(仍在开发中),需要在 div 中捕获用户选择的文本(不是文本区域和输入框,因此 .select 不起作用。)。 Using .click and selection and range objects works great when the selection is contained within a single element in that div but fails to trigger if the user selection spans multiple elements within the div (like multiple p's).
$('.relevantDivClass').click(function(){
console.log('Got here');
SelObj = window.getSelection();
Range = SelObj.getRangeAt(0);
if (SelObj.anchorNode == SelObj.focusNode){
console.log('executing same node branch');
string = SelObj.toString();
console.log(string)
}
else{
console.log('executing multiple node branch');
//code...
}
});
关于如何在这种情况下触发该事件的任何想法?它仍在相关DivClass 中,所以我很困惑为什么 .click 不会触发。
提前致谢!
【问题讨论】:
标签: javascript jquery javascript-events