avoid normal mouse-cursor movement on pressing enter in textarea
hi in my webpage i am saving textarea contents on pressing enter button . it is saving but what happens is mouse-cursor moves to next line . it always saves with a newline character . i just want to avoid the mouse-cursor moving to next line and just save it . for saving it i use event.keycode kind of stuff for the textarea and then save it
$('.text_desc_cls').keyup(function(event){save_text_val(event,this.id);});
function save_text_val(event,this_id){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){开发者_JAVA技巧
req_id = '#'+this_id;
textarea_val = $(req_id).val();
$.post("./funcs.php?func=save_int_text_val",{textarea_val:textarea_val},function(data){
alert('done');
}
}}
The easiest solution would be to grab the value on keydown - that will give you the value without the latest entry. It will show the newline in the textarea, so if you need that removed, you could switch to keyup rather than keydown and do a replace like so:
$(req_id).val($(req_id).val().replace(/\n/,''));
精彩评论