I'm having some field in which when the user types after 2nd alphabet, I need to add forward slash automatically. Is this possible in jquery?
<input type="text" class="someclass"/>
$(document).on('keyup','.classname', function(){
var count = $(this).val();
if(count == 2)
{
// Need stuff here
}
});
You can use:
$(document).on('keyup','.someclass', function(){
var count = $(this).val().length;
if(count == 2 && e.keyCode != 8){
$(this).focus().val(function( index, value ) { return value + "/ " ; });
}
});
You could do this:
$(document).on('keyup', '.someclass', function(e) { var count = $(this).val().length; if (count == 2) { $(this).val($(this).val() + "/"); } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" class="someclass" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.