jQuery's method of monitoring text box events and handling them accordingly
- 2020-05-30 19:25:27
- OfStack
This article illustrates how jQuery monitors text box events and handles them accordingly. Share with you for your reference. The details are as follows:
// Things entrusted
$(document)
.on('input propertychange', '#query', function(){
var input = $(this).val();
show(input);
});
var show = function(txt){
var info = ' Listening: <b>' + txt + '</b><br /><br />'
+ ' Related search: <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+' related '+i+'</span>';
};
}
return tag;
}
I hope this article has been helpful to your jQuery programming.