jQuery通过text值来设置选定,以及遍历select的选项个数和遍历

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

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

 

通过text值来设置select选定

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

 

遍历select

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

 

获取选项个数

$("#feedbackReason option").length;

 

posted on 2017-09-26 11:36  chenyangsocool  阅读(471)  评论(0编辑  收藏  举报