2014-10-10 197 views
0

我正在評論系統的狀態。我想通過按回車鍵評論狀態。 但是回覆沒有按下回車鍵。我在這裏的功能 -如何發表評論按回車鍵

$(document).ready(function() { 

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

     alert("send"); 
    } 
}); 
} 

輸入標籤是:

 <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];?>"/> 

即使我沒有收到警報這裏。我如何從輸入標籤獲取評論數據。

+5

$( 「#inputComment」)VAL()。錯過了報價? – senK 2014-10-10 12:10:59

+0

Thnaks @senK I已更正,但仍面臨同樣的問題。 – 2014-10-10 12:16:58

+1

如果你要發送整個表單,你可以使用隱藏的提交按鈕,如下所示:'' – 2014-10-10 12:17:18

回答

5

你犯了一些小錯誤。你忘了結束一個字符串,也結束了一些括號。

$(document).ready(function() { 
 
    $("#inputComment").keypress(function(e) { 
 
    if (e.which == 13) { 
 
     var val = $("#inputComment").val(); 
 
     alert("send"); 
 
    }   
 
    }); 
 
});
<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" />

+0

謝謝@AndreasFurster我正在申請這個。 – 2014-10-10 12:20:24

+0

如何通過jquey獲取這些額外的屬性值。 – 2014-10-10 12:30:24

+0

當您指'upd'和'uid'屬性時,您可以使用'$('#inputComment')。attr('upd')'。 – 2014-10-10 12:39:28