如何将 CSS 类名传递给 jQuery 自动完成组合框?

发布于 2024-12-17 00:24:50 字数 798 浏览 3 评论 0原文

jQuery Autocomplete 的工作原理是在页面上放置一个选择框并执行以下操作:

$(".myselect").combobox();

其中您的选择框附加了一个名为“myselect”的类。

combobox() 功能隐藏您的选择框,并在其位置放置一个文本框,并附加所有 jQuery UI 类。

我想要做的是绑定到“替换”选择框的框上的事件。我可以附加到该元素上存在的 jQuery UI 类之一:

<input class="ui-autocomplete-input ui-widget ui-widget-content ui-corner-left" 
       autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true"
       aria-describedby="ui-tooltip-0">

但是,我不想绑定到整个应用程序中的每个组合框文本框。有没有什么方法可以将类名传递给组合框(),以便让它将该类名传递到它生成的文本框?

更新:

不,这不是我要问的。我不知道如何动态地将类添加到正在渲染的输入框中。如果我可以添加一个类,那么我可以使用选择器附加到它。现在,我当然仍然可以使用选择器附加到它,但它会附加到我的应用程序其他部分中由组合框生成的每个输入框。我不想那样做。我只想绑定到这一页的输入框。

这个怎么样。如何使 jQuery AutoComplete 中的组合框示例在从组合框中选择值后发出“Hello”警报?

jQuery Autocomplete works by putting a select box on the page and doing this:

$(".myselect").combobox();

where your select box has a class attached to it called "myselect".

The combobox() functionality hides your select box, and puts a text box in its place with all of the jQuery UI classes attached.

What I want to do is bind to events on the box that "replaces" the select box. I could attach to one of the jQuery UI classes that are present on that element:

<input class="ui-autocomplete-input ui-widget ui-widget-content ui-corner-left" 
       autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true"
       aria-describedby="ui-tooltip-0">

However, I don't want to bind to EVERY combobox text box in my whole application. Is there som way to pass a class name to combobox() in order to have it pass that class name on to the text box that it generates?

UPDATE:

No, that's not what I'm asking. I can not figure out how to dynamically add a class to the input box that is being rendered. If I could add a class, then I could use a selector to attach to it. Right now, I sure could still use a selector to attach to it, but it would attach to EVERY input box that was generated by combobox in other parts of my application. I don't want to do that. I only want to bind to the input box on this one page.

How about this. How can I make the combobox example from jQuery AutoComplete put up an alert that says "Hello" after a value has been chosen from the combobox?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坏尐絯 2024-12-24 00:24:50

您应该能够在它生成的文本框中执行 addclass 并添加您想要的任何类。

$("#textboxId").addClass('className');

这应该会给你你所需要的。

You should be able to just do an addclass on the text box it generates and add whatever class you want.

$("#textboxId").addClass('className');

That should give you what you need.

新人笑 2024-12-24 00:24:50

选择实际上是一个

    如果您使用 CSS 选择器,

.ui-autocomplete .ui-menu-item{

}

您应该能够设置自动完成项目的样式。

The selection is actually a <ul> if you use the CSS selector

.ui-autocomplete .ui-menu-item{

}

you should be able to style your auto complete items.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文