taphold事件获取选定的单词

时间:2015-06-21 03:19:07

标签: jquery html jquery-mobile

如何在JQuery mobile中使用Taphold事件来提醒特定单词。

我现在可以获得整个

标记内容。

$("p").on("taphold",function(e){
    alert($(e.target));
});     

1 个答案:

答案 0 :(得分:1)

function get_selection() {
    var txt = '';
    if (window.getSelection) {
         txt = window.getSelection();
    } else if (document.getSelection) {
         txt = document.getSelection();
    } else if (document.selection) {
    txt = document.selection.createRange().text;
    }  
    return txt;
 }

 $(document).on("pagecreate","#pageone",function(){

 $(document).on("taphold",function(e){
     var select_text = get_selection();
     alert(select_text);
 });               
});
相关问题