如何在文本框上显示光标第一行

时间:2022-10-13 01:08:11

I want to show cursor first line of textbox if I press enter key. But always my cursor show in second line. please anyone can help me solving this problem. thanks

如果我按回车键,我想显示文本框的光标第一行。但总是我的光标显示在第二行。请任何人都可以帮我解决这个问题。谢谢

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>test page</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type="text/javascript">
   $(document).ready(function() {
   $('#txt_message').keydown(function (e){
    if(e.keyCode == 13 ){
    $('#txt_message').val("");
            }
})
});
</script>
    </head>
        <body>
 <textarea  id='txt_message'></textarea>
    </body>

</html>

1 个解决方案

#1


0  

 $('#txt_message').keydown(function (e){
    if(e.keyCode == 13 ){
    e.preventDefault();//use this to prevent default behavior 
    $('#txt_message').val("");
   }

demo js fiddle

演示js小提琴

#1


0  

 $('#txt_message').keydown(function (e){
    if(e.keyCode == 13 ){
    e.preventDefault();//use this to prevent default behavior 
    $('#txt_message').val("");
   }

demo js fiddle

演示js小提琴