在我的代码中,我有一个文本区域,在用户键入任何内容并按下回车键后,需要执行一些代码,但如果用户按下 shift+enter,那么新行应该只出现在文本区域中。到目前为止,下面是我的代码——
<textarea id="commentarea<?php echo $row[slno]; ?>" class="secondtextareay pull-left" rows="2" cols="50" placeholder="Post comments here..." onkeyup="enter_comment(<?php echo $row['slno']; ?>,<?php echo $CUID; ?>);"></textarea>
<script type="text/javascript">
function enter_comment(postid,userpostedid) {
if (event.which == 13) {
document.getElementById('commentarea'+postid).value='';
//insert_comment(id); // Call any function here: Just pass your actual Parameters to enter_comment().
}
else
{
return;
}
}
</script>
现在,当我按下 enter 时,它工作正常,但如果我按下 shift+enter,它也会做同样的事情。我想阻止这种情况,请帮忙。
最佳答案
if (event.keyCode == 13 && event.shiftKey) {
// shift+enter pressed
}
else if(event.keyCode == 13){
//enter key pressed
}else{
//nothing
}
关于javascript - 用于提交的 textarea keyup 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47279750/