up
down
Close
架站盒子
Web Development Box
 

jQuery 即時監聽 input 文字內容

│ 2207 Views │ jQuery
jQuery 即時監聽 input 文字內容
jQuery 即時監聽 input 文字內容

如果需要即時監聽使用者輸入input的內容,只需要使用on(input)即可。

HTML

<input type="text" id="text">

jQuery

$("#text").on("input", function() {
var text=$(this).val().trim();
console.log(val);
});

trim()代表去除前後空白。

實際操作

See the Pen Untitled by kumo (@kumo-tw) on CodePen.

延伸閱讀

本文是否對您有幫助?