提交最后编辑的输入字段后的jQuery焦点 [英] jQuery focus after submit on last input field edited

查看:74
本文介绍了提交最后编辑的输入字段后的jQuery焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在具有两个ID的jQuery keyup上,将执行一个函数.

On jQuery keyup on two IDs a function is executed.

$('#supplier_name').keyup(function(){
    clearTimeout(typingTimer);
    if ($('#supplier_name').val) {
        typingTimer = setTimeout(doneTyping, doneTypingInterval);
    }
    $.cookie("inputFocus", "#supplier_name"); 
});

此后,表单被提交.我想做一个jQuery,关注导致keyup函数执行的ID.

After this the form is submitted. I want to do jQuery .focus on the ID which led the keyup function to execute.

因此,如果我在提交表单后在#supplier_name中输入了文本,我希望重点放在该文本上.反之亦然,例如#aircraft_type.

So if I entered text into #supplier_name after form submit I want the focus to be on that. Vice versa with #aircraft_type.

我正在尝试通过cookie来执行此操作,但是它似乎不起作用.

I am trying to do this via cookies however it doesn't seem to be working.

如何使用以下jQuery代码做到这一点:

How do I do this with the following jQuery code:

<script>
$(document).ready(function() {
    $("#state").change(function () {
    this.form.submit();
})
$.cookie("inputFocus").focus();
$("#supplier_name").val($("#supplier_name").val());
$("#aircraft_type").val($("#aircraft_type").val());
var typingTimer;                
var doneTypingInterval = 800;  

$('#supplier_name').keyup(function(){
    clearTimeout(typingTimer);
    if ($('#supplier_name').val) {
        typingTimer = setTimeout(doneTyping, doneTypingInterval);
    }
    $.cookie("inputFocus", "#supplier_name"); 
});

$('#aircraft_type').keyup(function(){
    clearTimeout(typingTimer);
    if ($('#aircraft_type').val) {
        typingTimer = setTimeout(doneTyping, doneTypingInterval);
    }
    $.cookie("inputFocus", "#aircraft_type"); });

function doneTyping () {
    $("form").submit();
}

});
</script>

推荐答案

上述问题的解决方案是创建一个使用focus()的对象并添加jQquery cookie插件.

The solution to the above problem was to create an object to use focus() and to add the jQquery cookie plug-in.

更改如下: "$ .cookie(" inputFocus).focus();"到"$($.cookie(" inputFocus)).focus()"

The change is below: "$.cookie("inputFocus").focus();" to "$($.cookie("inputFocus")).focus()"

将以下代码添加到页面: "

Added the below code to the page: ""

这篇关于提交最后编辑的输入字段后的jQuery焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆