Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 仅在按下ENTER键时提交。_Php_Jquery - Fatal编程技术网

Php 仅在按下ENTER键时提交。

Php 仅在按下ENTER键时提交。,php,jquery,Php,Jquery,由于我不是jQuery专家,所以我很难让这个脚本正常工作。 这是我到目前为止得到的 按下ENTER键时,它不会发出警报 我希望这一切以一种非常Facebook的方式发生 我有一个带有id=“textboxcontent”的文本区域 我不知道我是否在正确的轨道上前进,但至少我尝试了=p var Id = element.attr("id"); $('input#textboxcontent'+Id).keypress(function(e) { if(e.keyCode ==

由于我不是jQuery专家,所以我很难让这个脚本正常工作。
这是我到目前为止得到的

按下ENTER键时,它不会发出警报

我希望这一切以一种非常Facebook的方式发生

我有一个带有
id=“textboxcontent”
的文本区域

我不知道我是否在正确的轨道上前进,但至少我尝试了=p

var Id = element.attr("id");
$('input#textboxcontent'+Id).keypress(function(e) {



        if(e.keyCode == 13) {
            e.preventDefault();
        var element = $(this);
        var Id = element.attr("id");
        var test = $("#textboxcontent"+Id).val();
        var dataString = 'comment='+ test + '&pid=' + Id;
        //var text = $(this).val();


        var commentContainer = $(this).parents('tr');

        if(test=='' || test == 'Write a Comment'){
            //==alert("Your comment can't be blank");
            //$("#textboxcontent"+Id).focus();
        } else {
            $("#flash"+Id).show();
            $("#flash"+Id).fadeIn(400).html('<img src="images/ajax-loader.gif" align="absmiddle"><font size="-2">chotto matte</font>');


            commentContainer.animate({ opacity : 0.5}, 500);
            commentContainer.find("#comment-loader").fadeIn(500);

                $.ajax({
                    type: "POST",
                    url: "http://localhost/rara/index.php/xtr/add_comment",
                    data: dataString,
                    cache: false,
                    success: function(html){
                        $("#loadplace"+Id).append(html);
                        //document.getElementById('textboxcontent' + +Id).value='';
                        $("#textboxcontent"+Id).attr( { value : " "  });
                        $('#textboxcontent').value='';
                        $("#flash"+Id).hide();

                        commentContainer.css({opacity : 1});

                        commentContainer.find("#comment-loader").fadeOut(100);
                        commentContainer.find('.panel').hide();
                        $(".comment-textarea").css({height : "30px" });
                        $('.delete-button').hide();



                    }
                });

        }

        } else {
            //alert
        }
          return false;
    });
var Id=element.attr(“Id”);
$('input#textboxcontent'+Id)。按键(功能(e){
如果(e.keyCode==13){
e、 预防默认值();
var元素=$(此);
var Id=element.attr(“Id”);
var test=$(“#textboxcontent”+Id).val();
var dataString='comment='+test+'&pid='+Id;
//var text=$(this.val();
var commentContainer=$(this.parents('tr');
if(test=''| | test=='写评论'){
//==警报(“您的评论不能为空”);
//$(“#textboxcontent”+Id).focus();
}否则{
$(“#flash”+Id).show();
$(“#flash”+Id).fadeIn(400.html('chotto matte');
动画({opacity:0.5},500);
commentContainer.find(“#注释加载器”).fadeIn(500);
$.ajax({
类型:“POST”,
url:“http://localhost/rara/index.php/xtr/add_comment",
数据:dataString,
cache:false,
成功:函数(html){
$(“#加载位置”+Id).append(html);
//document.getElementById('textboxcontent'++Id).value='';
$(#textboxcontent“+Id).attr({value:”});
$('#textboxcontent')。值='';
$(“#flash”+Id).hide();
css({opacity:1});
commentContainer.find(“#注释加载器”).fadeOut(100);
commentContainer.find('.panel').hide();
$(“.comment textarea”).css({height:“30px”});
$('.delete button').hide();
}
});
}
}否则{
//警觉的
}
返回false;
});
试试:

$('#textboxcontent')。按键(功能(e){ 如果(e.which==13){ //你的其他代码在这里
你需要简化你的问题。按键事件可以正常工作,后面的代码中一定有什么东西,或者你第一次从元素中读取id时是如何导致它不工作的。是@xxxo\u tryme的缩写:它提醒
enter
(Chrome) $('#textboxcontent').keypress(function(e) { if(e.which == 13) { //your other codes here