选择后jQuery的自动完成清除文本框中 [英] Clear text box in Jquery Autocomplete after selection

查看:188
本文介绍了选择后jQuery的自动完成清除文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要清除其jQuery的自动完成功能,一旦用户做出选择的文本框。

I want to clear the textbox having Jquery Autocomplete once the user has made the selection.

我试图来清除该字段:

select: function(event, ui) {
   $(this).val('');
}

但是,这并不working.I正在使用jQuery-1.6.4和jQuery-UI-16年1月8日。

But this is not working.I am using jquery-1.6.4 and jquery-ui-1.8.16.

任何想法?

推荐答案

借助选择事件之前发生的字段被更新。你将不得不取消该事件,以避免该领域正在更新已清除后:

The select event occurs before the field is updated. You will have to cancel the event to avoid the field being updated after you have cleared it:

select: function(event, ui) {
    $(this).val("");
    return false;
}

更新:的作为T.J.指出下面,它的速度稍快,以更新 DOM属性,而不是直接通过的 VAL()

Update: As T.J. pointed out below, it's slightly faster to update the value DOM property directly instead of going through val():

select: function(event, ui) {
    this.value = "";
    return false;
}

这篇关于选择后jQuery的自动完成清除文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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