@CharlieJustUs在使用Fiddle时会自动为您设置$变量。当脚本尝试在站点上运行时,该变量未设置,并且失败。
请试试这个。
jQuery(document).ready(function($) {
$(function() {
$(\'ul.clearfix\').each(function() {
var $select = $(\'<select class="dropdown-toggle" />\');
$(this).find(\'a\').each(function() {
var $option = $(\'<option />\');
$option.attr(\'value\', $(this).attr(\'href\')).html($(this).html());
$select.append($option);
});
$(this).replaceWith($select);
});
});
// This will grab the value the select is being set to and redirect to the link
$(\'select.dropdown-toggle\').on(\'change\', function(){
window.location.href = $( this ).val();
});
});