jquery mobile: what is proper way to programatically fire event on a jqm Select Menu -
jquery mobile: what is proper way to programatically fire event on a jqm Select Menu -
edit a: not jquery question, rather jquery mobile question.
edit b: changed title ... asked how fire 'click' event specifically, apparently 'click' event not proper event utilize if want re-create jqm:select menu choice.
how programatically fire event on jquery mobile select menu?
<select id = 'my_select' name = 'my_select' onchange = 'gf_handle_change( this.value );' > <option id = 'option_a' value = 'a'> </option> <option id = 'option_b' value = 'b'> b </option> </select> <script> function gf_fire_event( args_val ) { alert( 'test : ' + jquery( '#option_' + args_val ) ) ; jquery( '#option_' + args_val ).trigger( 'click' ) ; } function gf_handle_change( args_val ) { alert( args_val ) ; } gf_fire_event( 'a' ) ; </script>
this not work.
here's example:
$(document).on('pagebeforeshow', '#index', function(){ $("#test-button").on( "click", function(event, ui) { $('#my_select option#option_b').trigger('click'); }); $("#my_select option").each(function(){ $(this).on( "click", function(event, ui) { $(this).attr('selected' , true); $('#my_select').selectmenu('refresh'); }); }); });
working jsfiddle example: http://jsfiddle.net/gajotres/rz68b/
one more thing, not utilize onclick="... or onchange="... jquery mobile, case problems event triggering. bind event programatically.
jquery-mobile jquery
Comments
Post a Comment