获取选择的选项在jquery中选择元素id

时间:2016-03-27 16:54:46

标签: jquery

我想在文档准备就绪时选择选择元素选项的事件我使用下面的代码,但它返回library(dplyr) df1 %>% group_by(gr=cumsum(SALE_PRICE!= lag(SALE_PRICE, default=0))) %>% mutate(No_of_times=n()) %>% slice(1L) %>% ungroup() %>% select(-gr) # START_DATE ITEM_ID SALE_PRICE No_of_times # (chr) (int) (int) (int) #1 28-12-14 914602 0 4 #2 25-01-15 914602 2 1 #3 01-02-15 914602 0 2 #4 15-02-15 914602 2 3 #5 08-03-15 914602 0 1 #6 15-03-15 914602 2 6 的未定义值,请帮忙。

option:seleted

每次给出未定义的

1 个答案:

答案 0 :(得分:1)

使用jQuery

$(document).ready(function() { // you test if document is ready
  if ($("option:selected").length > 0) {
    // your code 
    alert($("option:selected").val());//use to get seleted option value
    alert($("option:selected").parent().val());//use to get selected option value using select
    alert($("option:selected").parent().attr("id"));//use to get select element id of selected:option
  }
});

See this fiddle