jquery设置select默认选中

jquery设置select默认选中,第1张

使用select标签的属性 selected。比如:

$('.select').find('option.active').attr('selected','selected')

需要准备的材料分别有:电脑、chrome浏览器、html编辑器

1、首先,打开html编辑器,新建一个html文件,例如:index.html,并引入jquery。

2、在index.html中的<script>标签,输入jquery代码:

$('select option').eq(1).attr('selected', true)

3、浏览器运行index.html页面,此时通过jquery设置了select的第二个option被选中。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/7846216.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-10
下一篇 2023-04-10

发表评论

登录后才能评论

评论列表(0条)

保存