如何在按回车键上发表评论

Rag*_*ngh 0 javascript php jquery

我正在制作关于状态的评论系统.我想按回车键评论状态.但是回复没有出现在媒体输入密钥上.这里我的功能 -

$(document).ready(function() {

$("#inputComment").keypress(function(e) {
    if(e.which == 13) {
        var val = $("#inputComment").val();

        alert("send");
    }
});
}
Run Code Online (Sandbox Code Playgroud)

输入标签是:

       <input type="text" class="form-control" id="inputComment"
                        placeholder="Add your comment"
                        upd="<?php echo $updates['data'][0][5];?>"
                        uid="<?php echo $userdata ['data'][0][1];?>"/>
Run Code Online (Sandbox Code Playgroud)

即使我在这里也没有警觉.如何从输入标签获取评论数据.

Nic*_*ler 5

你犯了一些小错误.你忘了结束一个字符串,也结束一些括号.

$(document).ready(function() {
  $("#inputComment").keypress(function(e) {
    if (e.which == 13) {
      var val = $("#inputComment").val();
      alert("send");
    }        
  });
});
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<input type="text" class="form-control" id="inputComment" placeholder="Add your comment" upd="1" uid="2" />
Run Code Online (Sandbox Code Playgroud)