突出显示文字时弹出消息

时间:2015-10-12 09:07:21

标签: javascript jquery html css

当用户试图突出显示并复制段落中的文本时,我试图找到一种显示弹出消息的方法。我在网上搜索可能的解决方案,但是当找到文本或段落的随机部分时,我找不到任何会触发弹出消息的消息。

我看了at this。但似乎它使用div块而不是弹出。

似乎@Nishit Maheta的答案解决了我的问题。不久我将用我的解决方案更新帖子。

3 个答案:

答案 0 :(得分:0)

试试这个:

tinyMCE.init({
    mode: "exact",
    elements: "test",
    skin: "o2k7",
    skin_variant: "red",

    setup: function (ed) {
        ed.onMouseUp.add(function (ed, e) {
            var x = tinyMCE.activeEditor.selection.getContent();
            if(x)
              alert(x);
        });
    }
});

<强> JSFIDDLE DEMO

答案 1 :(得分:0)

尝试Bootstrap Popover。以下是示例代码

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h3>Popover Example</h3>
  <p  data-toggle="popover" title="Popover Header" data-content="Some content inside the popover">Toggle popover</p>
</div>

<script>
$(document).ready(function(){
    $('[data-toggle="popover"]').popover();   
});
</script>

</body>
</html>

答案 2 :(得分:0)

这对我有用,希望它能解决您的问题。

&#13;
&#13;
 $("#myDiv").mousedown(function(){
    
              $("#myDiv").mouseup(function(){
    
                         $("#myPopUp").show();
              });
    });
&#13;
#myPopUp
{
    display:none;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="myDiv">
    hello please select the text and see
</div>
<div id="myPopUp">
    popover message
</div>
&#13;
&#13;
&#13;