如何检查光标是否位于文本区域内的空行上?
I don't care about word wrapping. I care about lines that were created by hitting Enter.
$('textarea').on("change keyup", function() {
if (cursor is on an empty line or the the line has just spaces) {
console.log("empty");
} else {
console.log("has stuff");
}
});
例如:
这会记录“有东西”
上面的行将记录“空”,这一行将记录“有东西”
下列should可以工作,但在旧版本的 IE 中不起作用。
// on(..., function() {
if( this.value.substr(0,this.selectionStart).match(/(?:^|\r?\n\s*)$/)
&& this.value.substr(this.selectionStart).match(/^(?:\s*\r?\n|$)/)) {
console.log("empty");
}
编辑搜索现在显式查找换行符,并且可以选择进一步的空格。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)