Html 如何使用角度分割输入文本框值
我有Html 如何使用角度分割输入文本框值,html,angularjs,Html,Angularjs,我有“*10/100”值,如何将该值分成三部分 像“HR”、“*”和“10/100” html <input type='text' ng-model='value' ng-change="GetAngValue(value)"> {{Result}} {{Result}} 棱角分明 $scope.GetAngValue = function (value) { var Matches = value.match
“
*10/100”
值,如何将该值分成三部分
像“HR”、“*”
和“10/100”
html
<input type='text' ng-model='value' ng-change="GetAngValue(value)">
{{Result}}
{{Result}}
棱角分明
$scope.GetAngValue = function (value) {
var Matches = value.match(/\<(.*?)\>/);
if (Matches) {
$scope.Result = Matches[1];
}
}
$scope.GetAngValue=函数(值){
var Matches=value.match(/\/);
如果(匹配){
$scope.Result=匹配[1];
}
}
我通过使用此代码获得角括号值,但如何获得剩余值还有很长的路要走,但它可以做到
value.replace("<","").replace(">",",").replace("*","*,").split(",");
value.replace(“,”,”).replace(“*”,“*,”).split(“,”);
{{Result}}
角度.module('app',[]).controller('appCtrl',function($scope){
$scope.GetAngValue=函数(值){
var Matches=value.replace(“,”,”).replace(“*”,“*,”).split(“,”);
如果(匹配){
$scope.Result=匹配项;
}
console.log(匹配项);
}
})
我得到的结果是这样的[“基本”、“*”、“10/100”]如何得到10/100的值。。不在双引号中是可能的吗?你所说的值是什么意思?你是说10/100是你想要得到的0.1吗?试着eval(“10/100”)得到0.1am,试着这样做var值=*10/100$scope.Matches=value.replace(“,”).replace(“,”).split(“,”)$scope.res=$scope.Matches[0]*(Math.floor($scope.Matches[2]);但如果我只给出10,它将返回null,这是在计算。。如果我使用的是null