hel*_*ing 12 wordpress jquery dialog
我试图在我的Wordpress主题管理页面中使用jQuery UI对话框脚本.一切都是直接来自UI演示,但我最终得到一个对话框,其中对话框没有弹出任何东西而是埋在底角,就在关闭正文标记之前.
UI对话框脚本与wp_enqueue_script正确排队,因为它在源代码中显示,如jquery(来自谷歌API)和UI核心.
jQuery(document).ready(function($) {
$("#dialog").dialog();
}); //end onload stuff
Run Code Online (Sandbox Code Playgroud)
然后我在我的选项页面中有这个:
<div id="dialog" title="Basic dialog">
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
Run Code Online (Sandbox Code Playgroud)
Pet*_*tai 30
你应该准备好了.WP已经有了对话框和样式.
以下是使用它的步骤:
dialogClass的wp-dialoginit使用正确的依赖项(jquery-ui-dialog)将上述文件排入队列wp-jquery-ui-dialog)例如:
// custom.js
jQuery(function($) {
var $info = $("#modal-content");
$info.dialog({
'dialogClass' : 'wp-dialog',
'modal' : true,
'autoOpen' : false,
'closeOnEscape' : true,
'buttons' : {
"Close": function() {
$(this).dialog('close');
}
}
});
$("#open-modal").click(function(event) {
event.preventDefault();
$info.dialog('open');
});
});
Run Code Online (Sandbox Code Playgroud)
在你的PHP中
add_action( 'admin_enqueue_scripts', 'queue_my_admin_scripts');
function queue_my_admin_scripts() {
wp_enqueue_script ( 'my-spiffy-miodal' , // handle
URL_TO_THE_JS_FILE , // source
array('jquery-ui-dialog')); // dependencies
// A style available in WP
wp_enqueue_style ( 'wp-jquery-ui-dialog');
}
Run Code Online (Sandbox Code Playgroud)
我管理使用以下代码显示对话框(但未应用样式!):
add_action('init', 'myplugin_load');
function myplugin_load(){
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-ui-core' );
wp_enqueue_script( 'jquery-ui-dialog' );
}
Run Code Online (Sandbox Code Playgroud)
使用时调用它:
$("#dialog-view").dialog({
height: 240,
modal: true
});
Run Code Online (Sandbox Code Playgroud)