简体   繁体   English

更清晰的jQuery文本框更改事件

[英]clearer jquery textbox change event

my apologies to ask this question as there may e answers already existing just that the weren't clear enough to me. 我很抱歉要问这个问题,因为可能答案已经存在,只是对我而言还不够清楚。 What is the best way to apply jquery change event on an html texbox control. 在html texbox控件上应用jquery change事件的最佳方法是什么。

Do you mean textarea? 你是说textarea吗? Something like this: 像这样:

$('textarea').on('keydown', function() {
    //Do stuff
    console.log('Do something smart here!');
});

Can you try the below sample code. 您可以尝试以下示例代码吗?

<input type="text" class="common" /> <input type =“ text” class =“ common” />

<input type="text" class="common" /> <input type =“ text” class =“ common” />

<input type="text" class="common" /> <input type =“ text” class =“ common” />

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" ></script> <script src =“ http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js”> </ script>

<script type="text/javascript"> <script type =“ text / javascript”>

 $(document).ready(function () {
     $("input.common[type='text']").change(function () {
        var value = this.value;
        alert(value);
     });
 });

</script> </ script>

On modern browsers, use oninput event: 在现代浏览器上,使用oninput事件:

$('textarea').on('input',function(event){
   alert(this.value);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM