繁体   English   中英

Wordpress '单击时未定义功能'

[英]Wordpress 'Function is not defined onclick'

我目前正在开发一个自定义 Wordpress 插件。 我必须使用这个特定的文件夹结构:

插件/ myplugin/ pdf.php

插件/myplugin/inlude/main.js

pdf.php 看起来像这样:

 function pdfmaker() {include('/wp-content/plugins/myplugin/include/main.js');   
    return '<button class="w-btn us-btn-style_3 us_custom_3a3dc668" type="button" value="Print_PDF" id="MakePDF delano" onclick="make_PDF()"> Print 
    PDF </button>'; }    add_shortcode('pdfmaker', 'pdfmaker'); 

但是每当我单击按钮时,我都会收到错误消息: Uncaught ReferenceError: make_PDF is not defined 即使我的 main.js 文件中有一个名为 make_PDF 的 function。

任何人都知道如何解决这个问题

它应该看起来像这样`

// First register resources with init 
add_action( 'init', 'myplugin_shortcode_resource' );

function myplugin_shortcode_resource() {
    wp_register_script("myplugin-shortcode-script",plugins_url("/include/main.js", __FILE__), ['jquery'], "1.0", false);

    //If you want a stylesheet ...
    wp_register_style("myplugin-shortcode-style", plugins_url("style.css", __FILE__), [], "1.0", "all");
}

add_shortcode( 'pdfmaker', 'pdfmaker' );

function pdfmaker() {
    wp_enqueue_script( 'jquery' );
    wp_enqueue_script("myplugin-shortcode-script",['jquery']);
    wp_enqueue_style("myplugin-shortcode-style");
    return '<button class="w-btn us-btn-style_3 us_custom_3a3dc668" type="button" value="Print_PDF" id="MakePDF delano" onclick="make_PDF()"> Print 
PDF </button>';
}

`

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM