jQuery监控文本框事件并作相应处理的方法

本文实例讲述了jQuery监控文本框事件并作相应处理的方法。分享给大家供大家参考。具体如下:

//事情委托
$(document)
 .on('input propertychange', '#query', function(){
  var input = $(this).val();
  show(input);
 });
 var show = function(txt){
  var info = '监听:<b>' + txt + '</b><br /><br />'
  + '相关搜索:<br />' + showTags(txt);
  $('.info').html(info);
 }
 var showTags = function(txt){
  var tag = '';
  if(txt.length){
   for (var i = 0; i < 3; i++) {
    tag += '<span class="tag">'+txt+'相关'+i+'</span>';
   };
  }
  return tag;
}
原文地址:https://www.cnblogs.com/sjqq/p/6392084.html