javascript - 将 2 个 JavaScript 合并为 1 个
问题描述
我正在为 Webscrape 做清理工作。
这是我当前的脚本。
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 个脚本以获得所需功能时遇到了困难。
解决方案
如果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];
推荐阅读
- django - 动作属性的 url 设置发生错误
- erlang - 是什么导致 Erlang 运行时错误 {undef,[{rand,uniform,[2],[]},...]}?
- javascript - 有什么办法可以提高网页的渲染速度?
- r - 删除自定义字符串并转换科学计数法
- python-3.x - 遗传算法的“独特”交叉 - TSP
- python - 将数据从一个 np.array 传输到另一个
- azure - 为 Azure Functions 配置日志级别
- javascript - 用户登录时如何显示注销
- python - 带有真正换行符的 Python repr 字符串
- .net - PDF 注释只读 .NET