jQuery keyup事件增加-“;函数“;将设置为0
jQuery keyup event increase-"function" will set to 0
我有三个输入字段来"搜索"JSON树。如果所有三个字段都已填充并正确,则从下一个JSON级别获取数据。
我通过keyup事件向上计数,以获得JSON树的下一个数据。但每当所有三个字段都被填满时,计数器就会重新设置种子。
HTML
<h1>sein</h1>
<form>
<input type="text" id=simple_present placeholder="simple present">
<input type="text" id=simple_past placeholder="simple past">
<input type="text" id=past_participle placeholder="past participle">
</form>
<div class="answerswer">Enter: be - was - been</div>
JS
$('input').on('keyup', function() {
var count = 0;
if (this.value === json.verbs.irregular[count++][this.id]) {
$(this).prop('disabled', true).next().focus();
}
if ($('input:not(:disabled)').length === 0) {
$('input').val('').prop('disabled', false).first().focus();
$('h1').text(json.verbs.irregular[count++].infinitiv);
alert(count);
}
});
也许每个关键事件的变量都会设置为0?但是我不能在keyup
-事件之外设置它!
这是我迄今为止所做的一个示范。
仅类型:
- be
- 是
- 一直
有什么想法吗?
你可以试试这个
var count = 0, amount = json.verbs.irregular.length-1, current = 0,
inputs = $("#simple_present, #simple_past, #past_participle");
$(inputs).on('keyup', function() {
if (this.value === json.verbs.irregular[count][this.id]) {
$(this).prop('disabled', true).next().focus();
}
if ($('input:not(:disabled)').length === 0) {
$('input').val('').prop('disabled', false).first().focus();
if(current < amount) {
current++; count++;
}
else {
current=0; count=0;
}
$('h1').text(json.verbs.irregular[current].infinitiv);
}
});
演示。
有一些工作:
http://jsfiddle.net/fantactuka/56VBk/
相关文章:
- 如何在页面加载时设置函数的条件
- 如何在Javascript中设置函数在上一次结束时启动
- 在对象中定义JavaScript获取和设置函数,而不使用“;这个“;
- 杰辛特 |传递默认设置 |函数声明和“this”
- 在运行时用JavaScript设置函数的名称
- 用对象设置函数变量's值
- 当我在tinmyce.int()中编写设置函数时,tinymce消失了,只有纯文本区域可见
- 如何使用JavaScript变量设置函数集css宽度
- Javascript;取消设置函数
- 设置函数图像样式
- 为什么我的设置函数之间的超时不起作用
- jQuery 设置函数执行前的等待时间
- 在Node.js中设置函数执行顺序
- 如何在javascript中设置函数的优先级
- 设置函数变量与使用对象文字相同
- 以 JavaScript 对象文字表示法设置函数的属性
- 使用jQuery's.prop方法来设置函数的属性
- 设置函数的超时时间
- 显式设置函数的返回类型
- 当bool值变为true时,如何设置函数调用