我是一个有用的助手,可以为您翻译文本。
我有一个简单的测验表单,其中包含几个输入和选择项,我需要测量参赛者编写/选择答案所花费的时间。
这是我尝试的方法,但它报告了不正确的时间:
我有一个简单的测验表单,其中包含几个输入和选择项,我需要测量参赛者编写/选择答案所花费的时间。
这是我尝试的方法,但它报告了不正确的时间:
$('input, select').on('focus', function(event) {
el = $(this);
name = el.attr('name'); // console.log(name);
a = performance.now();
a_value = el.val();
console.log(name + ' focused.');
$(el).on('input select cut copy paste', function(event) {
console.log('el: ' + el);
b_value = el.val();
if (a_value != b_value) {
b = performance.now();
if (name in times) {
console.log('exists');
times[name] = times[name] + (b - a);
} else {
times[name] = b - a;
}
}
});
$(el).on('blur', function(event) {
alert(times);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<input type="text" name="" id="">
<select name="" id="">
<option value="">option1</option>
<option value="">option2</option>
</select>
</body>
</html>