Detect selectmenu change in jquery mobile 1.4

I revise JQM after not using it for multiple versions.

I have a simple selectbox

<select name="current-option" id="current-option" class="current-option" data-native-menu="false">
        <option>Select Option</option>
        <option value="1">option 1</option>
        <option value="2">option 2</option>
    </select>

I want to be able to detect changes in this selection field and then read its value. It seems that the usual jquery methods do not work, and I do not see events in the api in this: http://api.jquerymobile.com/selectmenu/

+3
source share
4 answers

Well, you want to know the value of the parameter selected after the change event; You must do the following: -

$('#current-option').change(function () {
  var optionSelected = $(this).find('option:selected');
  //var optTextSelected = optionSelected.text();
  var optValueSelected = optionSelected.val();
});

I would ask you to change the names of names, identifiers and classes for your select tag.

+3
source

, : Fiddle

HTML

<select name="current-option" id="current-option" class="current-option" data-native-menu="false">
    <option>Select Option</option>
    <option value="1">option 1</option>
    <option value="2">option 2</option>
</select>
<label id='thelabel'></label>

JavaScript

$('#current-option').change(function () {
    $('#thelabel').text($(this).val());
});
+1

DOM . , select-menu div , id select; current-option-listbox. div , . , :

var currentValue = ""; // keep track of the selected value

$('.ui-btn-inner', '#current-option-listbox').click(function () {
    if ('a', this).text() !== currentValue) {
        // the value changed - do stuff
        currentValue = $(this).children('a').text();
    }
});

, , , , . , , .

0

"selectmenuchange", jQuery "change".

:

    $('#current-option').on('selectmenuchange',function () {
       $('#thelabel').text($(this).val());
    });
0

All Articles