通常我使用$(“#id”).val()来返回所选选项的值,但这一次它不起作用。 所选标记的id为aioConceptName

html代码

<label for="name">Name</label>
<input type="text" name="name" id="name" />

<label for="aioConceptName">AIO Concept Name</label>
<select id="aioConceptName">
    <option>choose io</option>
    <option>roma</option>
    <option>totti</option>
</select>

当前回答

这里有一个简单的解决方案。

$("select#aioConceptName").change(function () {
           var selectedaioConceptName = $('#aioConceptName').find(":selected").val();;
           console.log(selectedaioConceptName);
        });

其他回答

简单明了:

你下拉

<select id="aioConceptName">
    <option>choose io</option>
    <option>roma</option>
    <option>totti</option>
</select>

Jquery代码获取所选值

$('#aioConceptName').change(function() {
    var $option = $(this).find('option:selected');

    //Added with the EDIT
    var value = $option.val(); //returns the value of the selected option.
    var text = $option.text(); //returns the text of the selected option.
});
$('nameofDropDownList').prop('selectedIndex', whateverNumberasInt);

将DDL想象成一个带有索引的数组,您正在选择一个索引。选择一个你想用JS设置的。

试试这段代码::)

得到的值:

 $("#Ostans option:selected").val() + '.' + $("#shahrha option:selected").val()

得到文本:

 $("#Ostans option:selected").text() + '.' + $("#shahrha option:selected").text()

获取所选标签的值:

 $('#id_Of_Parent_Selected_Tag').find(":selected").val();

如果你想获取文本,请使用以下代码:

 $('#id_Of_Parent_Selected_Tag').find(":selected").text();

例如:

<div id="i_am_parent_of_select_tag">
<select>
        <option value="1">CR7</option>
        <option value="2">MESSI</option>
</select>
</div>


<script>
 $('#i_am_parent_of_select_tag').find(":selected").val();//OUTPUT:1 OR 2
 $('#i_am_parent_of_select_tag').find(":selected").text();//OUTPUT:CR7 OR MESSI
</script>

在这种情况下,你最好使用jQuery的change方法来查找当前选择的值,如下所示:

$('#aioConceptName').change(function(){

   //get the selected val using jQuery's 'this' method and assign to a var
   var selectedVal = $(this).val();

   //perform the rest of your operations using aforementioned var

});

我更喜欢这种方法,因为您可以在给定的选择字段中为每个选定的选项执行函数。

希望有帮助!