计算基于用户输入,标准是使用keyup
而不是change
或blur
.
问题是代码会在每次击键时触发,我需要它在500ms超时后才延迟和触发一次.我下面的例子显然不起作用,小提琴附件.
我找到了David Walsh的dbounce
功能,但无法弄清楚如何实现它.
HTML:
<input type="text" />
<input type="text" id="n2" class="num" value="17" disabled />
<input type="text" id="n3" class="num" value="32" disabled />
Run Code Online (Sandbox Code Playgroud)
使用Javascript/jQuery的:
$('input').keyup(function(){
var $this=$(this);
setTimeout(function(){
var n1 = $this.val();
var n2 = $('#n2').val();
var n3 = $('#n3').val();
var calc = n1 * n2 * n3;
alert(calc);
},500);
});
//http://davidwalsh.name/javascript-debounce-function
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = …
Run Code Online (Sandbox Code Playgroud) 我知道jQuery和jQuery-UI版本并不完美匹配.
例如,jQuery的当前"安全"版本是1.11.2,当前的"安全"jQueryUI是1.10.4
有时客户端要求继续使用特定版本的jQuery,例如1.8.3.我想使用jQuery-UI的"最新"版本,它将与特定版本的jQuery核心一起使用.
是否有某个文档可以映射最新版本的jQuery-UI,它将与给定版本的jQuery核心一起使用?
在多图表dc.js/d3.js演示文稿中,我希望用户点击第一个图表中的数据点,并且:
例如,用户在第一个图表上单击班次2.在那个班次上建造了140辆汽车.在图表1中,三个班次在该班次的生产的30个范围内:2,7,10.我希望将这3个数据点设为绿色,然后在图表2和图3中也使得转换为2,7,10绿色.(另外,原始点击的数据点应为红色)
我不确定如何将greendot类添加到三个图表中的这三个数据点.
clearconsole();
var chartWidth = 500;
var myCSV = [
{"shift":"1","date":"01/01/2016/08/00/00","car":"178","truck":"125","bike":"317","moto":"237"},
{"shift":"2","date":"01/01/2016/17/00/00","car":"125","truck":"189","bike":"125","moto":"273"},
{"shift":"3","date":"02/01/2016/08/00/00","car":"140","truck":"219","bike":"328","moto":"1252"},
{"shift":"4","date":"02/01/2016/17/00/00","car":"222","truck":"290","bike":"432","moto":"378"},
{"shift":"5","date":"03/01/2016/08/00/00","car":"200","truck":"250","bike":"420","moto":"319"},
{"shift":"6","date":"03/01/2016/17/00/00","car":"230","truck":"220","bike":"310","moto":"413"},
{"shift":"7","date":"04/01/2016/08/00/00","car":"155","truck":"177","bike":"377","moto":"180"},
{"shift":"8","date":"04/01/2016/17/00/00","car":"179","truck":"203","bike":"405","moto":"222"},
{"shift":"9","date":"05/01/2016/08/00/00","car":"208","truck":"185","bike":"360","moto":"195"},
{"shift":"10","date":"05/01/2016/17/00/00","car":"150","truck":"290","bike":"315","moto":"280"},
{"shift":"11","date":"06/01/2016/08/00/00","car":"200","truck":"220","bike":"350","moto":"205"},
{"shift":"12","date":"06/01/2016/17/00/00","car":"230","truck":"170","bike":"390","moto":"400"},
];
console.log('Click on a datapoint in chart1 to begin ');
lc1 = dc.lineChart("#line1");
lc2 = dc.lineChart("#line2");
lc3 = dc.lineChart("#line3");
var dateFormat = d3.time.format("%d/%m/%Y/%H/%M/%S");
myCSV.forEach(function (d) {
d.date = dateFormat.parse(d.date);
});
myCSV.forEach(function (d) {
d['car'] = +d['car'];
d['bike'] = +d['bike'];
d['moto'] = +d['moto'];
}); …
Run Code Online (Sandbox Code Playgroud)使用同一数据集的不同维度,屏幕上有三个dc.js折线图.
当用户在任何lineChart上单击数据点时,我希望找到并返回所有其他图表(包括单击的图表)中该对应点的数据值.
我也尝试(在鼠标悬停时)将圆形填充颜色更改为红色以用于悬停的数据点,以及所有其他图表的相应数据点(相同的"x"值).
我正在使用该.filter()
方法但未成功获取所需数据.错误消息是:"Uncaught TypeError: myCSV[i].filter is not a function"
lc1.on('renderlet', function(lc1) {
var allDots1 = lc1.selectAll('circle.dot');
var allDots2 = lc2.selectAll('circle.dot');
var allDots3 = lc3.selectAll('circle.dot');
allDots1.on('click', function(d) {
var d2find = d.x;
var d2find2 = d3.select(this).datum();
console.log(myCSV);
alert('Captured:'+"\nX-axis (Date): "+d2find2.x +"\nY-axis (Value): "+ d2find2.y +"\nDesired: display corresponding values from all three charts for this (date/time) datapoint");
allDots2.filter(d=>d.x == d2find2).attr('fill','red');
findAllPoints(d2find2);
});//END allDots1.on(click);
function findAllPoints(datum) {
var objOut = {};
var arrLines=['car','bike','moto'];
for (var i …
Run Code Online (Sandbox Code Playgroud)我希望在三个工作日前获得一个PHP日期.
我找到了很多通过各种文本方法获取日期的例子,但我找到的最接近的是这一个,但它返回三个日期(不是一个日期,三天前)并且需要一个get_holidays函数,代码不是提供.
如何在今天之前的三个工作日内编写PHP代码?
这有效,但不考虑周/周末日:
date('Y-m-d', strtotime('-3 days')); // returns 2012-12-01
Run Code Online (Sandbox Code Playgroud)
这不起作用,但我希望看到:
date('Y-m-d', strtotime('four week days ago'));
Run Code Online (Sandbox Code Playgroud)
事实上,上面的回报'1969-12-31'.就像这样:strtotime('-4 week days')
.
我的字母数字字符串总是以数字结尾,但可能会在早期嵌入其他数字。
我需要增加数字结尾并返回新的 ID 号。
例子:
A48-DBD7-398
Run Code Online (Sandbox Code Playgroud)
这将在循环中递增:
A48-DBD7-398
A48-DBD7-399
A48-DBD7-400
Run Code Online (Sandbox Code Playgroud)
如何将数字尾部与字符串的其余部分分开,然后将这两部分保存到不同的变量中?
我发现了其他几个将数字从字符串中分离出来的 SO 问题,但它们无法处理第一部分中的混合字母数字字符——否则它们会分离出所有数字,无论它们在哪里。我只需要获取尾随数字。
更新: 这个问题仍然存在
我发现我的解决方案不起作用的情况:
ABC123-DE45-1
Run Code Online (Sandbox Code Playgroud)
重复如下:
ABC2
ABC3
ABC4
Run Code Online (Sandbox Code Playgroud)
尝试使用样本数据中3列的最小值,最大值和平均值创建d3/dc/xfilter dataTable.一直在苦苦挣扎但无法理解如何将reduceAdd,reduceRemove,reduceInitial函数集成到dataTable中以创建三个必要的行.
期望的输出将如下所示:
------------------------------------------
| Value | Cars | Bikes | Trucks |
------------------------------------------
| Min | 125 | 310 | 189 |
------------------------------------------
| Max | 230 | 445 | 290 |
------------------------------------------
| Avg | 178 | 385 | 245 |
------------------------------------------
Run Code Online (Sandbox Code Playgroud)
也看不出如何添加第一个(标签)列.我知道reduceInitial可以返回一个数组(例如['min', 'max', 'avg']
)但是如何引用它的标签?
var myCSV = [
{"shift":"1","date":"01/01/2016/08/00/00","car":"178","truck":"255","bike":"317","moto":"237"},
{"shift":"2","date":"01/01/2016/17/00/00","car":"125","truck":"189","bike":"445","moto":"273"},
{"shift":"3","date":"02/01/2016/08/00/00","car":"140","truck":"219","bike":"328","moto":"412"},
{"shift":"4","date":"02/01/2016/17/00/00","car":"222","truck":"290","bike":"432","moto":"378"},
{"shift":"5","date":"03/01/2016/08/00/00","car":"200","truck":"250","bike":"420","moto":"319"},
{"shift":"6","date":"03/01/2016/17/00/00","car":"230","truck":"220","bike":"310","moto":"413"},
{"shift":"7","date":"04/01/2016/08/00/00","car":"155","truck":"177","bike":"377","moto":"180"},
{"shift":"8","date":"04/01/2016/17/00/00","car":"179","truck":"203","bike":"405","moto":"222"},
{"shift":"9","date":"05/01/2016/08/00/00","car":"208","truck":"185","bike":"360","moto":"195"},
{"shift":"10","date":"05/01/2016/17/00/00","car":"150","truck":"290","bike":"315","moto":"280"},
{"shift":"11","date":"06/01/2016/08/00/00","car":"200","truck":"220","bike":"350","moto":"205"},
{"shift":"12","date":"06/01/2016/17/00/00","car":"230","truck":"170","bike":"390","moto":"400"},
];
dataTable = dc.dataTable('#dataTable');
lc1 = dc.lineChart("#line1");
lc2 = dc.lineChart("#line2");
lc3 = dc.lineChart("#line3");
var dateFormat …
Run Code Online (Sandbox Code Playgroud)使用VSCode编写/测试python,在调试模式下会发生问题。
数个更新之前,VSCode开始在插入活动代码窗口的大红色框中显示当前的堆栈跟踪错误报告。我可以在终端中关闭它,但现在还可以-我似乎无法关闭它。
问题是我处于调试模式,所以当前的变量值在悬停时仍然存在并且可见,并且我希望悬停不同的变量,但是红色的大框占用了大部分屏幕空间。
(1)有没有办法在保持调试模式的同时关闭盒子?(单击红色方框停止调试时,它将自动关闭)
(2)是否有可能在用户设置中关闭此新功能的方法?(也就是说,是否将错误消息留在终端窗口中?)
(3)如果不是-有人知道是否为此打开了github问题?(是的,我搜索了,但是没有看到,但是也许这个东西没有正确地称为big red box
-我还应该搜索其他东西吗?
使用 archiver.js(用于 Node.js),我需要从递归(多子目录)存档中排除图像。这是我的代码:
const zip = archiver('zip', { zlib: { level: 9 } });
const output = await fs.createWriteStream(`backup/${fileName}.zip`);
res.setHeader('Content-disposition', `attachment; filename=${fileName}.zip`);
res.setHeader('Content-type', 'application/download');
output.on('close', function () {
res.download(`backup/${fileName}.zip`, `${fileName}.zip`);
});
output.on('end', function () {
res.download(`backup/${fileName}.zip`, `${fileName}.zip`);
});
zip.pipe(output);
zip.glob('**/*',
{
cwd: 'user_uploads',
ignore: ['*.jpg', '*.png', '*.webp', '*.bmp'],
},
{});
zip.finalize();
Run Code Online (Sandbox Code Playgroud)
问题是它没有排除忽略文件。如何更正语法?
javascript ×4
dc.js ×3
jquery ×3
archiverjs ×1
crossfilter ×1
d3.js ×1
jquery-ui ×1
node.js ×1
php ×1
reactjs ×1
tampermonkey ×1
userscripts ×1