尝试像这样更改代码。。希望它能起作用
function sam()
{
wp_enqueue_script(\'wp-color-picker\', plugins_url(\'wp-color-picker-script.js\', __FILE__ ), array( \'farbtastic\' ), false, true );
}
add_action( \'admin_enqueue_scripts\', \'sam\' );
在模板中
<div class="color-picker" style="position: relative;">
<input type="text" value="#bada55" class="ir" id="color" />
<div style="position: absolute;" id="colorpicker"></div>
</div>
在js文件中(wp color picker script.js)
jQuery(document).ready(function($) {
$(\'#colorpicker\').hide();
$(\'#colorpicker\').farbtastic(\'#color\');
if ( $("#color").val().length === 0 )
{
var input = $( "#color" );
input.val( input.val() + "#ffffff" );
}
$(\'#color\').click(function() {
$(\'#colorpicker\').fadeIn();
});
$(document).mousedown(function() {
$(\'#colorpicker\').each(function() {
var display = $(this).css(\'display\');
if ( display == \'block\' )
$(this).fadeOut();
});
});
});