更改textarea中选择的行

时间:2013-04-07 21:35:18

标签: javascript jquery textarea

我正在使用jquery来显示textarea旁边的行。 从这个链接: http://alan.blog-city.com/jquerylinedtextarea.htm

是否有任何方法可以更改所选行,因此每次用户转到下一行时,所选行都会更改为当前行。

$(function() 
{
    // Target all classed with ".lined"
    $(".lined").linedtextarea(
    {
        //change it from 1 to the current line that the user on.
        selectedLine: 1
    });

    // Target a single one
    $("#mytextarea").linedtextarea();

});

1 个答案:

答案 0 :(得分:0)

是的,

function selectLine(n) {
    if (n<1) return false; //If the total number of lines is known it is worth checking you are not above it either
    $(".codelines .lineno.lineselect").removeClass("lineselect")
    $(".codelines .lineno").eq(n-1).addClass("lineselect");
}

有很多jQuery插件(当它们在jQuery小部件上完整时)你可以使用“options”方法来做这类事情,比如$(".lined").linedtextarea("options",{selectedLine: 6})但它看起来并没有像这样进入一个小部件。这个解决方案是一种逆向工程,因为mod使用lineselect类来控制突出显示的行号。

我们做了一些检查,以确保我们将使用一个合理的值,从已有的任何行中删除高亮类,并将其添加到第n-1行号div(-1因为eq是基于零)。

如果您在一个页面上有多个带衬里的文本框,则无效。如果是这种情况,我们需要添加另一个参数来定义哪个目标和一些处理它的逻辑。