将提交按钮与输入键集成按下以注释框

Yah*_*hoo 0 html javascript forms jquery this

我在我的页面中使用10个评论框.按钮工作完美但现在我想添加功能,当我按下回车按钮然后自动提交文本.

如何在不更改代码的情况下添加此功能.我将bsubmit类绑定到事件On click.(有10个评论框)

    <div class="addcomment" style="display: block; ">
<input class="commentadd" type="text" name="comment" value="Enter Comment" onfocus="if(this.value=='Enter Comment')this.value='';">
<button class="bsubmit" type="button">Submit</button></div>
Run Code Online (Sandbox Code Playgroud)

活动代码

 $(document).ready(function() {

$(function() {
$(".bsubmit").live("click", function() {
var id = $(this).parent().parent().attr("id");
var comm= document.getElementById(id).getElementsByClassName("commentadd")[0].value;


  $.ajax({
   type: "POST",
   url: "comment.php",
.
.
.
Run Code Online (Sandbox Code Playgroud)

the*_*dox 5

$('body').on('keyup','input.commentadd', function(e) {
  // e.which is monitoring the key pressed 
  // and 13 is code for enter key
  if(e.which == 13 && $.trim(this.value).length) {
    $(this).next(".bsubmit").click(); // triggering click event on button
  }
});
Run Code Online (Sandbox Code Playgroud)

DEMO