将2个JavaScript合并为1个

问题描述 投票:0回答:1

我正在为Web Scraper做清理工作。

这是我目前的剧本。

var cleanup = function(results) {
 $.each(results, function(){
  this.values[0] = this.values[0].replace("Submission date: ", 
  "").split(" ")[0];
    this.values[1] = this.values[1].replace("Case number: ", "");
 });
  return results;  
  };

然后我发现我需要添加

  var d = "2010-10-30".slice(0, 10).split('-');   
  d[1] +'/'+ d[2] +'/'+ d[0]; // 10/30/2010

为了改变数据的写入方式。我目前的输出是YYYY-MM-DD,需要是MM/DD/YYYY

我在组合2个脚本以获得所需功能时遇到了困难。

javascript
1个回答
0
投票

如果this.values[0]是有问题的属性并且现在包含YYYY-MM-DD形式的日期值(在删除Submission date:文本的行之后),那么它应该像这样简单:

 // take the date value from the field & split it
 var d = this.values[0].slice(0, 10).split('-');
 // assign the parts in new order and concatenated with the separator / back to the field
 this.values[0] = d[1] +'/'+ d[2] +'/'+ d[0];
© www.soinside.com 2019 - 2024. All rights reserved.