0
我想建立一個WordPress插件,將從鼠標懸停事件的表中獲取與帖子相關的數據,並將其附加到另一個div。我設法寫了一個零代碼,不理解js和PHP。難以排隊在wordpress插件腳本
我安裝並激活了插件,但js沒有加載到頁面上。我沒有正確排列腳本嗎?我也想實現以下目標:腳本只能在桌面上加載,因此不適用於移動設備。
任何幫助或指針在正確的方向將是偉大的!
我的PHP代碼
<?php
/* PLUGIN INFO */
function sknv_ea_return(){
$ea_id = isset($_POST['post_id']) ? $_POST['post_id'] : 0;
if ($ea_id > 0)
{
$ea_post = get_post($ea_id);
?>
<div id="ea_post"><?php echo $ea_post->post_content; ?></div>
<?php
}
die();
}
add_action('wp_ajax_nopriv_sknv_ea','sknv_ea_return');
function sknv_ea_get_scripts()
{
wp_enqueue_script(plugins_url('sknv_ea.js', __FILE__));
}
add_action('wp_enqueue_scripts', 'sknv_ea_get_scripts');
?>
和我的JS代碼
jQuery(document).ready(function ($) {
$("tr.emcustom").onmouseover(function() {
var div = $(this);
$.post('wp-admin/amdin-ajax.php' , {
action: "sknv_ea",
event_id: $(this).find("a").attr("id")
}, function (data) {
$("#agenda_title").append($(data));
}
);
return false;
});
$("tr.emcustom").mouseout(function() {
$("ea_post").remove();
});
});
這工作!我認爲代碼有問題。謝謝分配!我的dekstop-mobile問題上的任何指針可能? – Sam
@Sam我更新了我的答案。 – FluffyKitten