0

我正在使用 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();

});
4

1 回答 1

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 小部件上充满时),您可以使用“选项”方法来做这种事情,$(".lined").linedtextarea("options",{selectedLine: 6})但看起来它并没有变成一个小部件。这个解决方案是一种逆向工程,因为 mod 使用 lineselect 类来控制突出显示的行号。

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

如果您在一页上有多个带行的文本框,这将不起作用。如果是这种情况,我们需要添加另一个参数来定义要定位哪个参数以及一些处理它的逻辑。

于 2013-04-08T00:00:55.213 回答