1. 程式人生 > >獲取select的option值及其文本

獲取select的option值及其文本

query jquer strong 選擇 cti val gpo 及其 edi

在jQuery中選擇select標簽的方法有:

$("#selectId") 和 $("select[name=‘selectName‘]")

1.獲取select選擇的值,選擇了select之後直接用val():

例如:$("#selectId").val()或者$("select[name=‘selectName‘]").val();

2.獲取select的文本值,選擇了select之後,用find():

例如:$("#selectId").find("option:selected").text();或者$("select[name=‘selectName‘]").find("option:selected").text();

3.獲取select選中的索引

例如:$("#selectId").get(0).selectedindex;

獲取select的option值及其文本