ace编辑器文本中的可点击url div

时间:2014-01-02 18:18:15

标签: javascript ace-editor

我有一个ace编辑器“textarea”,在里面我有一个类“ace_underline”。这个跨度基本上是一个url,我希望能够捕获它上面的mouseup事件。

我知道我可以抓住这样的东西

 editor.on("click", function(evt) { //something; });

但我希望只有当我点击“ace_underline”范围时才能检测到。 有人可以帮我这个吗?

谢谢!

2 个答案:

答案 0 :(得分:2)

我认为我发现它,在某些情况下仍然需要一些修复,但它正在起作用:

var handler = function(e){
    var editor = e.editor;

    var pos = editor.getCursorPosition();
    var token = editor.session.getTokenAt(pos.row, pos.column);
    if (/\bmarkup.underline\b/.test(token.type)) { 
            window.open(token.value); // opens the link
        }

}
Editor.on("click", handler);

基于此:github link

答案 1 :(得分:0)

你可以使用一个字符串作为.on()的第二个参数,它是父元素中元素的选择器:

$(editor).on('click', 'span.ace_underline', function(evt) {
    // $(this) is the span element
});