下拉当前索引 onchange
有一个包含 5 个选项的下拉菜单。当前,选择了选项 2。用户现在选择了选项 4。onchange 事件被触发,该事件被 JS 函数捕获,监听选择上的 onchange。
在 JS 函数中,我可以使用 selectedIndex 属性轻松检查用户选择的选项的索引。但是,我还想知道用户更改它的原始值是什么。
是否存在持续存在的属性 基本上是原始值,即 在这种情况下选择 2。
there is a dropdown with 5 options. Currently,option 2 is selected.The user selects option 4 now.The onchange event gets fired which is caught in a JS function listening for onchange on the select.
In the JS function, I can check easily the index of the option selected by the user using the selectedIndex property.However, I want to also know what was the original value that the user changed it from.
Is there a property that persists
basically the original value i.e.
option 2 in this case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
作为一个概念,我将以下内容放在一起 - 很可能有更好的方法来做到这一点:
--
封闭示例:
我试图将这一切与实际的下拉元素本身联系起来。老实说,这是我第一次向下拉菜单本身添加功能,所以我不能保证这不会产生后果:
Just as a concept I put together the following - there may very well be a better way to do this:
--
Closed-up Example:
I've tried to tie this all into the actual drop-down element itself. In all honesty, this is the first time I've ever add functions to the dropdown itself, so I cannot promise that this won't have consequences:
不,您需要将其保留在 js 变量中。
No, you would need to persist that yourself in a js variable.
正如 dl 所说,您可以使用简单的隐藏变量来保存值。我们可以在隐藏变量中设置当前值。
使用 onfocus="setPrevious(this.id)" 设置当前值
JS
使用 Onchange() 检查确认按钮输出并设置“前一个”值
As told by dl, you can use simple hidden variable to hold the value.We can set the current value in hidden varaible.
Use onfocus="setPrevious(this.id)" to set the current value
JS
Use Onchange() to check the confirm button output and set the "previous" value