我的jquery函数在边栏中工作得很好:)。在侧栏中拖动小部件后启用Jquery。
jQuery( document ).ajaxComplete( function( event, XMLHttpRequest, ajaxOptions ) {
var request = {}, pairs = ajaxOptions.data.split(\'&\'), i, split, widget;
for( i in pairs ) {
split = pairs[i].split( \'=\' );
request[decodeURIComponent( split[0] )] = decodeURIComponent( split[1] );
}
if( request.action && ( request.action === \'save-widget\' ) ) {
widget = jQuery(\'input.widget-id[value="\' + request[\'widget-id\'] + \'"]\').parents(\'.widget\');
if( !XMLHttpRequest.responseText )
wpWidgets.save(widget, 0, 1, 0);
else
jQuery(\'.selector\').on(\'change\', change_image);
function change_image(){
var $path = jQuery(this).find(\'option:selected\').val();
jQuery(\'.image_path\').attr(\'src\',$path);
}
}
});