javascript - How to prevent only closing of bootstrap modal on backspace keypress -
i have form in bootstrap modal. have disabled backspace button when bootstrap modal open code
$('body').keydown(function (e) { if ($('#mymodal').is(':visible')) { if (e.keycode == 8) { return false; } } });
in bootstrap modal form have textbox, textarea need backspace button there. not able use backspace button in textbox in bootstrap modal form
solution:
$('body').keydown(function (e) { if ($('#mymodal').is(':visible')) { var rx = /input|select|textarea/i; if (e.keycode == 8) { if(!rx.test(e.target.tagname) || e.target.disabled || e.target.readonly ){ e.preventdefault(); } } } });
Comments
Post a Comment