角度-换行文本
Angular - Break line text
我无法将换行符文本保存到数据库中,如何解决此问题?
我的保存数据应该是这样的
I want to ask something.
Can I?
不像这个
I want to ask something. Can I?
html
<textarea name="" cols="" rows="" class="form-control" ng-model="rule.message" required></textarea>
<button type="submit" class="btn btn-default" ng-click="create()">Save</button>
js
myControllers.controller('MemberRuleCreateCtrl', ['$scope', '$location',
'$http',
function($scope, $location, $http) {
$scope.rule = {};
$scope.create = function() {
$http({
method: 'GET',
url: 'http://xxxxx.my/api/create_rule.php?&message=' + $scope.rule.message
}).
success(function(data, status, headers, config) {
alert("Rule successful created");
$location.path('/member/rule');
}).
error(function(data, status, headers, config) {
alert("No internet connection.");
});
}
}
]);
只需使用encodeURIComponent()
函数将换行符正确编码到URL中,这样在提交GET请求时服务器就能正确地看到换行符。
所以你的JS变成了:
myControllers.controller('MemberRuleCreateCtrl', ['$scope', '$location',
'$http',
function($scope, $location, $http) {
$scope.rule = {};
$scope.create = function() {
$http({
method: 'GET',
url: 'http://xxxxx.my/api/create_rule.php?&message=' + encodeURIComponent($scope.rule.message)
}).
success(function(data, status, headers, config) {
alert("Rule successful created");
$location.path('/member/rule');
}).
error(function(data, status, headers, config) {
alert("No internet connection.");
});
}
}
]);
相关文章:
- Internet Explorer中的文本换行错误
- 使用jQuery的输入字段文本换行
- 脚本图像获胜't用文本换行
- D3具有矩形和文本换行的水平树布局
- 标记内的文本换行
- 使用 jQuery 将文本换行在
标记内 - 如何在文本换行时在图像下方保留填充
- 溢出隐藏不会文本换行
- d3.js径向树布局可变节点长度/文本换行节点描述
- 如何手动管理HTML中的文本换行
- jQuery动画slidelleft没有文本换行
- 将文本换行到并由
使用jquery - 文本换行到列
- 如何在文本换行时减少字母间距
- 文本换行选项-建议
- 围绕span文本换行元素
- 在Polymer 1.0中带有绑定的文本换行元素
- Var文本换行或任何格式不工作
- 如何在javascript中拖动图像/元素时导致实时文本换行
- 使用 javascript/jquery 将带有强标签的文本区域中突出显示的文本换行