2017-10-31 16 views
0

私はJavaScriptを使用してテキストエリアにユーザーの入力を防ぐためにしようとしているに入力することを防止しようとしています。TEXTAREA

なぜこれは機能しませんか?

$("textarea").on("input", function (e) { 
    console.log("returning"); //This prints 
    e.preventDefault(); 
    return false; 
    //Even though this code runs when text is inputed into the textarea, it still doesn't prevent user input. Shouldn't returning false do that? 
}); 
+0

https://stackoverflow.com/questions/32298064/preventdefault-not-working-in-on-input-function – Bsalex

+0

の重複 'keydown'の代わりに、入力 – emil

+0

入力イベントが発生してみてください_after_コントロールに入力があります。 https://developer.mozilla.org/docs/Web/Events/input _から引用 - ,