$('#test option[text="b"]').attr("selected",true);  

上面的方法在 jquery 低于 1.4.2 的版本(含)中有效,在更高版本中无效!

例如:

<select name="number" id="test">
<option value="">a</option>
<option value="">b</option>
</select>

jquery 版本

<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>

解决一:精确匹配,选择文本与所给字符串完全一样的option。

$('#test option').filter(function(){return $(this).text()=="b";}).attr("selected",true);  

解决二:子串匹配,选择文本包含所给字符串的option。

$("#test option:contains('b')").attr('selected', true);  

最新文章

  1. 总结-Hibernate
  2. linux命令-find {查找}
  3. XtraBackup原理解读
  4. Post model至Web Api创建或是保存数据
  5. C#制作验证码
  6. HDU 4782 Beautiful Soup --模拟
  7. 二级指针的作用及用途 .xml
  8. AVA取整以及四舍五入
  9. 检索表中所有列的名称、DB中的用户表
  10. JVM之---Java内存分配参数(第四篇)
  11. python【第三篇】函数
  12. 寻找失踪的整数数组(Find the missing integer)
  13. 【Sqlserver系列】初级思维导图
  14. 我从业11年来遇到的最奇葩的raid0+1数据恢复经历
  15. vue中computed、metfods、watch的区别
  16. 干货 | SSMS客户端连接京东云RDS SQL Server配置方法
  17. 子弹短信光鲜的背后:网易云信首席架构师分享亿级IM平台的技术实践
  18. Go For It ,一个灵活的待办事项列表程序
  19. angular2.0学习笔记7.echarts 地图(type:&#39;map&#39;)slice undifined 出错问题
  20. nginx mac 下启动 停止 重启,查看安装位置

热门文章

  1. Android:finish()与System.exit(0)之间的区别
  2. Scala的Higher-Kinded类型
  3. 记坑: ConfigurationProperties 和 RefreshScope
  4. webpack4.x开发环境配置
  5. C# 对 TCP 客户端的状态封装
  6. 基于tp3开发的cms-前台代码执行
  7. Spring Cloud 学习 之 Spring Cloud Eureka(架构)
  8. input在IOS中的聚焦问题
  9. [hdu5593 ZYB&#39;s Tree] 树上统计
  10. HDU 3874 Necklace 区间查询的离线操作