首页 > 技术文章 > jQuery通过text值来设置选定,以及遍历select的选项个数和遍历

chenyangsocool 2017-09-26 11:36 原文

真是醉了,网上搜了很久,全都是千篇一律的。

大家都拷贝来拷贝去,全是错的。

 

通过text值来设置select选定

$("#CompanyID").find("option:contains('a')").attr("selected", true);

 

遍历select

$("#feedbackReason option").each(function() {
    console.log($(this).val());
});

 

获取选项个数

$("#feedbackReason option").length;

 

推荐阅读