1

我正在为 iOS 和 Android 构建一个混合应用程序,并且有一个部分我想展示这一天。如果您在星期二打开应用程序,它会显示星期二,以此类推。它是西班牙语,所以,它写着“Miércoles”的地方是星期三,但我是手动写的,我希望它改变,所以如果今天是星期三,它会自动改变。

我尝试使用 ng-bind 和以下代码更改它:

    var today = new Date();
  if(today.getDay() == 0){
    var hoy = "Domingo";
  } else if(today.getDay() == 1){
    var hoy = "Lunes";
  }else if(today.getDay() == 2){
    var hoy = "Martes";
  }else if(today.getDay() == 3){
    var hoy = "Miercoles";
  }else if(today.getDay() == 4){
    var hoy = "Jueves";
  }else if(today.getDay() == 5){
    var hoy = "Viernes";
  }else if(today.getDay() == 6){
    var hoy = "Sábado";
  }
  $scrope.variable = hoy;

它不起作用,没有控制台错误或警告。

显示我的应用的图片

4

3 回答 3

4

您多次声明同一个变量,因此第一次之后的声明将被忽略。

使用这样的工作日数组看起来会更好:

var now = new Date();
//var weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var weekday = ["Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes","Sábado"];

var hoy = weekday[now.getDay()];
$scope.variable = hoy;
于 2016-08-18T02:31:21.713 回答
1

看起来你有一个错字。

从改变

$scrope.variable = hoy;

$scope.variable = hoy;

于 2016-08-18T02:29:47.197 回答
1

只需更新您的代码,

var today = new Date(),
    weekday = [ 
                "Domingo",
                "Lunes",
                "Martes",
                "Miercoles",
                "Jueves",
                "Viernes",
                "Sábado"
              ];

var hoy = weekday[today.getDay()];
$scope.variable = hoy;

演示:https ://jsfiddle.net/1a148yrw/2/

于 2016-08-18T02:38:28.097 回答