rem*_*dy. 1 html javascript php angularjs
我有以下html:
<div class="form-group">
<div class="input-group col-sm-12">
<label for="" class="control-label">Comments</label>
<div class="controls">
<textarea id="txtArea" rows="10" cols="50" ng-model="$parent.comments" type="text" ng-trim="false"></textarea>
{{comments}}
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
在我的js控制器内部是以下内容:
$scope.updateComments = function()
{
$http({
method: 'POST',
url: '/create_comment/' + $scope.id+ '?comments=' + $scope.comments,
})
.success(function(data){
$('#myModalComment').modal('hide');
})
}
Run Code Online (Sandbox Code Playgroud)
问题是,每当我处理textarea输入中的换行符时,它都不会处理。
例如,如果我想输入以下行:
first line
second line
Run Code Online (Sandbox Code Playgroud)
我的输出想要这样:
第一行第二行
我该如何解决这个问题?
更新:
万一这可能是PHP掩盖html字符的后端问题,这是我的php控制器内部的函数:
public function createComments($id)
{
$comments = Input::get('comments');
$log= Logger::find($id);
$log->comments= $comments;
$log->save();
}
Run Code Online (Sandbox Code Playgroud)
如果我确实正确了解您,则问题可能出在以下几行:
<textarea id="txtArea" rows="10" cols="50"
ng-model="$parent.comments" type="text" ng-trim="false"></textarea>
{{comments}}
Run Code Online (Sandbox Code Playgroud)
该{{comments}}是没有显示换行符。
但这是自然的HTML行为。还有自然的HTML解决方案<pre>:
<textarea id="txtArea" rows="10" cols="50"
ng-model="$parent.comments" type="text" ng-trim="false"></textarea>
<pre>{{comments}}</pre>
Run Code Online (Sandbox Code Playgroud)
参见http://www.w3schools.com/tags/tag_pre.asp:
该
<pre>标签定义预格式化文本。
<pre>元素中的文本以固定宽度的字体(通常为Courier)显示,并且保留空格和换行符。