如何通过使用jQuery单击按钮来选择下拉列表中的所有值? [英] How to select all values in drop down list by clicking a button using jQuery?

查看:65
本文介绍了如何通过使用jQuery单击按钮来选择下拉列表中的所有值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过在JavaScript中使用jQuery单击按钮来选择下拉列表中的所有值?

How to select all values in drop down list by clicking a button using jQuery in JavaScript?

推荐答案

此解决方案适用于普通的多选列表和具有optgroup的多选列表.

This solution works with plain multi-select lists and multi-select lists that have optgroups.

$("select option").attr("selected", "true");

注意:这是HTML答案,对于选定的XHTML,它应等于"selected",而不是true.

Note: This is the HTML answer, for XHTML selected should equal "selected", rather than true.

这篇关于如何通过使用jQuery单击按钮来选择下拉列表中的所有值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆