You can use jQuery's trigger() method to respond to events
Definition and usage
The trigger() method triggers the specified event type of the selected element.
Syntax
$(selector).trigger(event,[param1,param2,...])
Parameter description
event Required. Specifies the event to be triggered by the specified element. You can make custom events (attached using bind() function), or any standard event.
[param1,param2,...] Optional. Additional parameters passed to the event handler procedure. The extra parameters are especially useful for custom events.
Example:
Trigger the change event of the select element:
$("button").click(function(){ $("select").trigger("change"); });
$("#selectId").change(function(){ alert("选中的值为:"+$(this).val()); });
Give the select an id attribute
<select id="sel"></select> $("#sel").bind("onchange",function(){ //自己写代码,这个就是给select空间添加onchange事件 });
function changeProtocol() { $('#step4 #protocol').empty(); $('#step4 # protocol').append("<option value='"+key+"'>"+value+"</option>"); }
Clear the select first, Then reset the option. After this process is completed, how to trigger the change event?
$("#step #protocol").change();
$('#step4 #protocol').trigger('change')
$('#step4 # protocol ').bind('change',function(){});
The above is the detailed content of Detailed explanation of how to trigger select's change event code in jquery. For more information, please follow other related articles on the PHP Chinese website!