使jQuery元素在加载后(在完成页面加载后)执行
答案 0 :(得分:0)
事件。当您使用其他自定义事件进行初始化时,例如“刷新”:
/*! -- ui-slider -- */ $(document).on('ready reload',function() { $( "#slider" ).slider({ range: true, min: 0, max: 500, values: [ 25, 450 ], slide: function( event, ui ) { $( "#value" ).val( "" + ui.values[ 0 ] + " - " + ui.values[ 1 ] ); } }); $( "#value" ).val( "" + $( "#slider" ).slider( "values", 0 ) + " - " + $( "#slider" ).slider( "values", 1 ) ); }); /*! -- toggleclass -- */ $(document).on('ready reload',function() { $("#div3").on('click', '.toggle', function () { $(this).toggleClass("toggle_background"); }); });
....然后你只需要在$.load()
$(document).ready(function(){ $("#selectbox").change(function(){ var selectedOption = $('#selectbox :selected').val(); $containerDiv = $('#receive_content'); $containerDiv.html(""); switch (selectedOption) { case "Selectbox":$containerDiv.load( "default" , function(){$(document).trigger('reload');} ); break; case "Option 1":$containerDiv.load( "content.html #div1" , function(){$(document).trigger('reload');}); break; case "Option 2":$containerDiv.load( "content.html #div2" , function(){$(document).trigger('reload');}); break; case "Option 3":$containerDiv.load( "content.html #div3" , function(){$(document).trigger('reload');}); break; } return true; }); });