当用户选择“下拉列表”时触发什么 jQuery?选项
我想为该下拉列表的不同选择显示不同的表单:
<label>
<select name="type" id="type">
<option value="object" selected="selected">Object</option>
<option value="number">Number</option>
<option value="text">Text</option>
<option value="date">Date</option>
<option value="time">Time</option>
<option value="geo">Geospatial</option>
<option value="currency">Currency</option>
</select>
</label>
当用户选择这些选项之一时触发的 jQuery 事件是什么。在这种情况下,.click() 事件也会被触发吗?
I want to display a different form for different selections of this drop down list:
<label>
<select name="type" id="type">
<option value="object" selected="selected">Object</option>
<option value="number">Number</option>
<option value="text">Text</option>
<option value="date">Date</option>
<option value="time">Time</option>
<option value="geo">Geospatial</option>
<option value="currency">Currency</option>
</select>
</label>
What would be the jQuery event that is triggered when a user selects one of these options. Would the .click() event be triggered in this case as well?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用
change
事件。每次鼠标单击都会触发单击,这不是您想要的,即使用户单击组合但不更改值也会触发单击。另外,
click
不利于键盘导航,因此change
是正确的方法:You should use the
change
event. Click will be triggered on every mouse click, which is not what you want, and it'll be triggered even if the user clicks on the combo but doesn't change the value.Also,
click
won't be good for keyboard navigation, sochange
is the way to go: