监听textarea标签的实时输入

1,385 阅读1分钟

html

<textarea class="commit" name="" id="" cols="30" rows="10"></textarea><input type="button" value="发布" class="send" disabled>

jQuery内的change事件只有在元素失焦后才会被触发,所以只能用事件委托来实时监听

js

  $('body').delegate('.commit','propertychange input',function(){    if($(this).val().length > 0){      $('.send').prop("disabled",false)    }else{      $('.send').prop("disabled",true)    }