用于预选下拉值的 YUI 自定义事件?

发布于 2024-08-16 19:21:23 字数 345 浏览 4 评论 0原文

我有一个下拉字段,其值在呈现后立即被预先选择(例如,它是注册表单中的国家/地区字段)。我还有其他下拉列表或其他组件,可以动态更改第一个下拉列表的选定值。现在我想用下拉列表中的每个“选择值”来触发一个方法。是否可以?

为了更清楚地表达我的问题,我想创建一个 onDefaultValueSet 事件并订阅第一个下拉列表。因此,无论下拉列表以何种方式选择任何值,都会调用相应的处理程序(我的函数)。

我尝试使用 YUI 自定义事件来做到这一点,但我不确定每次在下拉列表中选择一个值时浏览器将如何调用(理解)我的处理程序。

我想 onSelect (来自默认 DOM)不是一个正确的答案,因为我尝试过。

请帮助我解决这个问题。

I have a dropdown field and its value is pre-selected as soon as its rendered (Say, its a Country field in a signup form). And I have other dropdowns or other components which change the selected value of the first dropdown dynamically. Now I want to fire a method with every "value getting selected" in the dropdown. Is it possible?

To put my question in much more clearer way, I want to create a onDefaultValueSet event and subscribe the first dropdown to it. So in which ever way the dropdown gets any value selected, the corresponding handler (my function) gets called.

I tried to do it with YUI Custom Events, but I am not sure how the browser will be calling(understanding) my handler every time a value is selected in the dropdown.

onSelect (from Default DOM) is not a right answer I guess, as I tried it.

Please help me in tackling this problem.

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

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

发布评论

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

评论(1

被你宠の有点坏 2024-08-23 19:21:23

我不确定这是否是答案,但我找到了解决方法。请验证这一点。

所以我使用 javascript-dom 操作来“选择”一个项目。意思是,使用

domElement.options[5].selected = True;

因此,通过我创建的 (YUI)自定义事件,我在此之后立即开始调用“fire()” 。所以代码变成:

domElement.options[5].selected = True;
onDefaultValueSetEvent.fire(domElement.name);

但我不确定,如果以 GUI 方式选择特定选项会怎样。意思是,如何自动调用 fire() 方法

I am not sure whether this is an answer, but I've found a workaround. Please validate this.

So I was making a item "selected" using javascript-dom manipulation. Meaning, using

domElement.options[5].selected = True;

So with the (YUI)custom event I created, I started calling "fire()" right after this. So the code becomes:

domElement.options[5].selected = True;
onDefaultValueSetEvent.fire(domElement.name);

But I am not sure, what if the particular option is selected in a gui fashion. Meaning, how automatically fire() method is called

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