gpt4 book ai didi

function - 如何在文本区域中按回车键时调用函数。这是我的代码 :

转载 作者:行者123 更新时间:2023-12-02 03:44:08 25 4
gpt4 key购买 nike

当用户在文本区域中按下回车键时,我想调用 insert_comment() 函数:与 facebook 相同。

<form action="" method="post" enctype="multipart/form-data" name="comment_form" id="comment_form">
<tr>
<td colspan="3" align="left" valign="top"><textarea name="comment_text" id="comment_text_<?php echo $i; ?>" class="valid Post_Description_Text" placeholder="Write a comment here..."></textarea></td>
</tr>
<tr>
<td colspan="3" align="right" valign="top"><span id="extra_small_round_loader_<?php echo $postID; ?>"></span>&nbsp;<input type="button" name="comment" value="Comment" id="comment" onclick="insert_comment(<?php echo $i; ?>);" /></td>
</tr>
</form>

下面是函数 insert_comment() 我想在文本区域中按下回车键时调用:

<script type="text/javascript">
function insert_comment(id)
{
var comment_des = $("#comment_text_"+id).val();
var fk_post_id = $("#fk_post_id_"+id).val();
var post_user_id = $("#post_user_id_"+id).val();
var user_id = $("#user_id_"+id).val();

$.post('ajax_files/insert_comment.php', {comment_des:comment_des,user_id:user_id,fk_post_id:fk_post_id,post_user_id:post_user_id},
function(data)
{
//$("#ajaxdata").html(data);
$("#extra_small_round_loader_"+fk_post_id).empty().html('<img src="images/extra_small_round_loader.gif">');
$('#reload_posts').load('ajax_files/reload_posts.php');


});
}
</script>

已解决:好的,每个人我都找到了解决方案,我测试了它并且它工作完美。

这是 Textarea 字段:

<textarea name="comment_text" id="comment_text_<?php echo $i; ?>"  class="valid Post_Description_Text" placeholder="Write a comment here..." onkeyup="enter_comment(event,<?php echo $i; ?>);"></textarea>

还有函数:

<script type="text/javascript">
function enter_comment(event,id) {
if (event.which == 13) {
insert_comment(id); // Call any function here: Just pass your actual Parameters to enter_comment().
}

}
</script>

最佳答案

尝试向您的文本区域添加一个 onkeyup 处理程序:

onkeyup="if(event.keyCode==13) insert_comment(<?php echo $i; ?>);"

关于function - 如何在文本区域中按回车键时调用函数。这是我的代码 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18201261/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com