当我按下返回键为帖子开始一个新行时,结果会自动忽略它。例如,我按下'a'键'return'键'b',打印出'ab'。但我需要'a b'我想知道如何解决它?
我尝试$comment = nl2br($comment)
,但无效。
以下是我刚刚进行测试的演示。
php文件(linebreak.php)
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<div id="comment_box" contenteditable="true" autocomplete="off" spellcheck="false" placeholder="How do you feel about?"></div>
<div id="post_comment" class="comment_leg">Post</div>
<div name="commentsubmit"></div>
<style>
#comment_box{
text-align: center;
background-color: white;
/*position:relative;*/
border: 1px solid orange;
/*height:60px;*/
width: 500px;
padding: 10px;
color:black;
border-radius:3px;
/*font-size:18px;*/
display: inline-block;
text-align: left;
vertical-align: bottom;
/*border-color:yellow;*/
}
.comment_leg{
cursor:pointer;
width:60px;
/*height:18px;*/
background-color: #ffcc99;
padding:5px;
text-align: center;
border-radius: 3px;
display:hide;
vertical-align: bottom;
display: inline-block;
}
</style>
<script>
$(function(){
$("#post_comment").click(function(){
var txt = $("#comment_box").text();
if(txt){
$.post("commenttest.php", {txt: txt}, function(result){
$("div[name=commentsubmit]").prepend(result);
$("#comment_box").text('');
});
}
})
})
</script>
php文件(commenttest.php)
<?php
$comment=$_POST["txt"];
echo "<div style='color:orange'>".$comment."</div>"
?>