2016-08-12 23 views
-1

我正在学习一个jQuery.My的问题是当我点击编辑按钮然后特​​定的下拉值显示我选择。这个选择的值我想存储在jQuery中,所以我如何存储它?我有附加图像请帮助我。 enter image description here如何获取没有更改值的下拉值?

+1

目前还不清楚你问什么,但'VAL()'方法应达到什么样的,你需要 –

+0

请发布代码'选择'而不是图片/屏幕截图! – Pugazh

回答

0

尝试

对于选定值

var selected_value= $('.service_select').val(); 

对于下拉

var all_values= $('.service_select option').map(function(obj){ 
    return $(obj).attr('value'); 
}); 

的所有选项的值对于键值对所有选项的值

var all_values= {}; 
$('.service_select option').each(function(){ 
    all_values[$(this).attr('value')]=$(this).text(); 
}); 
1

$('select').val()会为您提供value属性。

如果您希望所选选项的文本使用$('select').find(':selected').text()

下面是一个例子:

$(function() { 
 
    //Get the selected value 
 
    console.log($('.service_select').val()); 
 

 
    //Captures the selected value when the selection changes 
 
    $('.service_select').change(function() { 
 
    console.log($(this).val()); 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<select name="service_select" class="service_select"> 
 
    <option value="0">-- Select --</option> 
 
    <option value="1">Option 1</option> 
 
    <option value="2">Option 2</option> 
 
    <option value="3">Option 3</option> 
 
</select>