触发器('change') 选择第一个选项,这是我不想要的
我有一个有多个选项的选择。没有空选项。
在调用触发器之前,没有选择任何选项,之后它运行时,第一个选项被预先选择,我希望选择保持原样,没有选择任何选项
$("#selProduct").trigger('change');
如何解决这个问题? 我仍然想触发更改以运行事件,但我不想选择第一个选项。
I have a select that has several options. No empty option.
Before calling the trigger none of the options are selected, after it runs the first option is preselected, and I want that the select to stay as it was, no option selected
$("#selProduct").trigger('change');
How to fix this?
I still want to trigger the change, to run the events, but I do not want the first option selected.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您看到的是 DOM 被触摸后的结果,并且取决于浏览器(但是
selectedIndex
应该 已经是0
)。也就是说,使用
.triggerHandler()
来运行 只是处理程序,如下所示:对于您的问题,您可能希望在页面加载时在
I think what you're seeing is the result of the DOM once it's touched and will depend on the browser (but
selectedIndex
should be0
already).That being, said, use
.triggerHandler()
to run just the handler, like this:For your question though, you may want to store something on the
<select>
on page-load, that changes when it's "touched", for example: