Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.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
Javascript 将注释框中的textarea替换为可编辑的div_Javascript_Jquery_Html - Fatal编程技术网

Javascript 将注释框中的textarea替换为可编辑的div

Javascript 将注释框中的textarea替换为可编辑的div,javascript,jquery,html,Javascript,Jquery,Html,注释框与配合得很好,但我需要使用div来代替它。 以下是文本区号: <textarea class="commentMark" id="commentMark-<?php echo $row['p_id'];?>" onblur="if (this.value=='') this.value = 'Write a comment'" onfocus="if (this.value=='Write a comment') this.value = ''" onKeyPress=

注释框与
配合得很好,但我需要使用
div
来代替它。 以下是文本区号:

<textarea class="commentMark" id="commentMark-<?php  echo $row['p_id'];?>" onblur="if (this.value=='') this.value = 'Write a comment'" onfocus="if (this.value=='Write a comment') this.value = ''" onKeyPress="return SubmitComment(this,event)" wrap="hard" name="commentMark" style=" background-color:#fff; overflow: hidden;" cols="60">Write a comment</textarea>
但在文本区,当我按enter键时,评论会被发布。当我进入div时,它不会产生任何效果


单击“注释”按钮时,div也会出现

为什么不使用
文本区域
?您可以在按下enter键时创建新行,避免提交表单-请使用本机javascript或jQuery附加事件处理程序。过度使用onclick
onkeypress
等使我成为一只悲伤的熊猫。@martincarlin87:我对textare有意见。使用
div
我可以在文本中提供
readmore
选项。但是在文本区我不知道阅读更多部分做什么?一般来说,你应该能够通过一个文本区域实现你想要的,如果需要的话,把它设计成不像一个。@martincarlin87:是的,你是对的。当textarea的内容超过特定大小时,它只会显示几行。当用户单击查看更多时,只应显示整个内容。请看
<div class="commentMark" id="commentMark-<?php  echo $row['p_id'];?>" onblur="if (this.value=='') this.value = 'Write a comment'" onfocus="if (this.value=='Write a comment') this.value = ''" onKeyPress="return SubmitComment(this,event)" wrap="hard" name="commentMark" style=" background-color:#fff; overflow: hidden;" cols="60">Write a comment</div>