Javascript 在点后加空格
你好。我有点问题。 我在那里写了一些信息 例如:Javascript 在点后加空格,javascript,angularjs,Javascript,Angularjs,你好。我有点问题。 我在那里写了一些信息 例如: <div class="wizard wizardstep1" ng-controller='someCtrl'> <p class="wizardtitle">Put you Theme</p> <input id="taskTheme" required type="text" placeholder="Put you Theme" ng-model="taskThem
<div class="wizard wizardstep1" ng-controller='someCtrl'>
<p class="wizardtitle">Put you Theme</p>
<input id="taskTheme" required type="text" placeholder="Put you Theme" ng-model="taskThemeWizardInputValue" ng-change="checkThemeWizardInputValue()">
</div>
为您呈现主题
我有我的控制器
例如:
$scope.checkThemeWizardInputValue = function () {
if ($scope.taskThemeWizardInputValue === undefined) {
$scope.taskThemeWizardInputValue = "";
console.log($scope.taskThemeWizardInputValue);
console.log($scope.taskThemeWizardInputValue.length);
} else {
var strt = $scope.taskThemeWizardInputValue.split('.');
for (var i = 0 ; i < strt.length; i++) {
strt[i] = strt[i].charAt(0).toUpperCase() + strt[i].substr(1);
}
$scope.taskThemeWizardInputValue = strt.join('.');
console.log($scope.taskThemeWizardInputValue);
console.log(strt);
}
}
$scope.checkThemeWizardInputValue=函数(){
如果($scope.taskThemeWizardInputValue==未定义){
$scope.taskThemeWizardInputValue=“”;
log($scope.taskThemeWizardInputValue);
log($scope.taskThemeWizardInputValue.length);
}否则{
var strt=$scope.taskThemeWizardInputValue.split('.');
对于(变量i=0;i
如何在点后添加空格?谁知道呢
您只需将
strt.join('.')
更改为strt.join('.')
$scope.checkThemeWizardInputValue=function(){
如果($scope.taskThemeWizardInputValue==未定义){
$scope.taskThemeWizardInputValue=“”;
log($scope.taskThemeWizardInputValue);
log($scope.taskThemeWizardInputValue.length);
}否则{
var strt=$scope.taskThemeWizardInputValue.split('.');
对于(变量i=0;i0){
strt[i]=''+strt[i].charAt(0).toUpperCase()+strt[i].substr(1);
}
}
$scope.taskThemeWizardInputValue=strt.join('.');
log($scope.taskThemeWizardInputValue);
控制台日志(strt);
}
}
这是有效的我建议创建一个指令
,以便您可以在需要时插入此行为,而不是在每个控制器中编写ng更改
在指令简单行element.val(event.target.value.split(“.”)和join(“.”)中代码>将在指令控制器
参数的帮助下为您工作
参见示例我们通过为每个拆分的字符串(第一个字符串和一个空字符串除外)添加空间来实现它
函数someCtrl($scope){
$scope.checkThemeWizardInputValue=函数(){
如果($scope.taskThemeWizardInputValue==未定义){
$scope.taskThemeWizardInputValue=“”;
log($scope.taskThemeWizardInputValue);
log($scope.taskThemeWizardInputValue.length);
}否则{
var strt=$scope.taskThemeWizardInputValue.split('.');
对于(变量i=0;i0&&strt[i].trim().length>0){
addSpace='';
}
strt[i]=addSpace+strt[i].trim().charAt(0).toUpperCase()+strt[i].trim().substr(1);
}
$scope.taskThemeWizardInputValue=strt.join('.');
log($scope.taskThemeWizardInputValue);
控制台日志(strt);
}
}
}
为您呈现主题
您想在哪一行进行更改?请加入我的答案。所以您想这样退出:Abc。Def。Bhi?是的,我必须删除我在使用Backspace时写的所有内容。不幸的是,我不能不喜欢你的回答。因为首先看一下你是如何加入工作的,然后再写一个工作的例子。一秒钟你可以不用一秒钟就完成,一秒钟你就可以完成。但退格的问题仍然存在。现在我无法在单词之间留出空格。不正确,你说不能腾出空间是什么意思?
$scope.checkThemeWizardInputValue = function () {
if ($scope.taskThemeWizardInputValue === undefined) {
$scope.taskThemeWizardInputValue = "";
console.log($scope.taskThemeWizardInputValue);
console.log($scope.taskThemeWizardInputValue.length);
} else {
var strt = $scope.taskThemeWizardInputValue.split('.');
for (var i = 0 ; i < strt.length; i++) {
strt[i] = strt[i].trim();
if(strt[i].length > 0) {
strt[i] = ' '+strt[i].charAt(0).toUpperCase() + strt[i].substr(1);
}
}
$scope.taskThemeWizardInputValue = strt.join('.');
console.log($scope.taskThemeWizardInputValue);
console.log(strt);
}
}