JQuery自动完成帮助 [英] JQuery Autocomplete help

查看:67
本文介绍了JQuery自动完成帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的JQuery自动完成控件,声明是这样的。

I have a customised JQuery autocomplete control that is declared something like this.

$('#SystemCode_Autocomplete').autocomplete({
    source: [{"label":"Access","value":0},{"label":"Documentum","value":0}], //move values
    minLength: 1,
    change: function(event, ui) {// some function},
    select: function(event, ui) {// some function}
});

更改和选择事件是自定义的。
问题是如果我在文本框中键入内容然后单击提交按钮(即没有标签输出或丢失焦点),或者如果我在键入文本框后按键提交,则更改事件不是在我提交之前必须解雇。

The change and select events are custom. The problem is if I type something into the textbox then click the submit button (i.e. no tab out, or lost of focus), or if I press the key to submit after typing into the text box, the change event isn't fired and it has to be before I submit.

我希望不用将javascript放在提交按钮后面,并且理想情况下从自动完成中执行此操作控制自己。我尝试将更改添加到模糊事件。

I was hoping to do it without putting javascript behind the submit button, and to ideally do it from within the autocomplete control itself. I tried adding the change to the blur event.

${'foo').blur(function() { $('bar').trigger('autocompletechange');
// or
${'foo').blur(function() { $('bar').change();

但他们都没有工作,有人有任何想法吗?

But none of them have worked, anyone have any ideas?

推荐答案

你可以尝试这样的事情:

You can try something like this:

$('#SystemCode_Autocomplete').autocomplete({
    source: [{"label":"Access","value":0},{"label":"Documentum","value":0}], //move values
    minLength: 1,
    change: function(event, ui) {/* some function */},
    select: function(event, ui) {/* some function */}
}).each(function(){
    var self = $(this).closest("form").submit(function(e){
        self.trigger("change");

        // you may not need anything like this...but whatever
        if(!functionToCheckIfFormIsValid()){
            e.preventDefault();
        }
    });
});

这篇关于JQuery自动完成帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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