如何檢查光標是否位於textarea內的空行上?如何檢查遊標是否在textarea內的空行上?
我不在乎單詞包裝。我關注通過點擊輸入創建的線條。
$('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");
}
});
例如:
這將日誌 「有東西」
線上面會記錄 「空」 與這條線將日誌 「有東西」
因爲我知道JavaScript是不可能的 – gogagubi
一個空行可能是由於包裝和CR/LF生成的。你關心哪個? –
我能想到的唯一方法(計算字符數)取決於瀏覽器在textarea中使用等寬字體,這不能再保證。 – Blazemonger