English 中文(简体)
在 Enter 键键按键中整合提交提交按钮以获取注释框
原标题:Integrating submit button with on Enter key press for comment box

我正使用我的页面中的 10 个注释框。 按钮完美运作, 但现在我想添加功能, 当我按下输入按钮时, 文本自动提交 。

如何在不更改很多代码的情况下添加此函数 。 我用“ 点击上” 活动约束了 bsubsub 类 。 (有 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>

花 花 花 花 花 花 花 花 花 花 花

 $(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",
.
.
.
最佳回答
$( 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
  }
});

http://jsfidd.net/FrAw8/7, rel=“notfollow” >DEMO

问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签