<分区>
Possible Duplicate:
Find out the 'line' (row) number of the cursor in a textarea
我想在 HTML textarea
元素中找出用户光标所在的行号。
这可以使用 javascript 和 jquery 吗?
<分区>
Possible Duplicate:
Find out the 'line' (row) number of the cursor in a textarea
我想在 HTML textarea
元素中找出用户光标所在的行号。
这可以使用 javascript 和 jquery 吗?
最佳答案
这适用于按钮点击。从 Find out the 'line' (row) number of the cursor in a textarea 被盗
function getline()
{
var t = $("#t")[0];
alert(t.value.substr(0, t.selectionStart).split("\n").length);
}
HTML
<textarea rows="6" id="t">
there is no
love in the ghetto
so come here
and get it
</textarea>
<input type="button" onclick="getline()" value="get line" />
关于javascript - 获取文本区域中的行号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12553025/