JS获取文件名 - 字符串操作 substring() indexOf()

$scope.imgSrc = '1.jpg';
$scope.next = function(){
  var num = parseInt($scope.imgSrc.substring(0,$scope.imgSrc.indexOf('.')));
  num = num<4 ? num+1 : 1;
  $scope.imgSrc = num+'.jpg';
}
$scope.prev = function(){
  var num = parseInt($scope.imgSrc.substring(0,$scope.imgSrc.indexOf('.')));
  num = num<2 ? 4 : num-1;
  $scope.imgSrc = num+'.jpg';
}
posted @ 2020-10-04 19:12  wing1377  阅读(209)  评论(0编辑  收藏  举报