Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Wordpress主题中添加javascript函数时遇到问题_Javascript_Php_Wordpress - Fatal编程技术网

在Wordpress主题中添加javascript函数时遇到问题

在Wordpress主题中添加javascript函数时遇到问题,javascript,php,wordpress,Javascript,Php,Wordpress,我试图在wordpress主题页面中包含一个javscript函数/插件。我只是想让插件在一个特定的页面上工作,因为它应该是一种日历插件 所以现在我开始使用主题的functions.php文件中的wp_enqueue_脚本函数。这是代码的样子: function spacious_scripts(){ wp_enqueue_script('LaunchWS', get_template_directory_uri(). '/js/wsLaunch.js'); } add_action ('wp_

我试图在wordpress主题页面中包含一个javscript函数/插件。我只是想让插件在一个特定的页面上工作,因为它应该是一种日历插件

所以现在我开始使用主题的functions.php文件中的wp_enqueue_脚本函数。这是代码的样子:

function spacious_scripts(){
wp_enqueue_script('LaunchWS', get_template_directory_uri(). '/js/wsLaunch.js');
}
add_action ('wp_enqueue_scripts', 'spacious_scripts');
我还继续使用这个插件的创建者提供给我的脚本创建了一个js文件(如果脚本被破坏,我会包括它,我对javascript还是新手): 文件名为:“wslaunch.js”,函数名为:“launchWS”

<script type="text/javascript">
function launchWS(winName) { 
    //window height and width
    myHeight = screen.height*.80;
    myWidth = 784;
    //widow height bounds
    if ( myHeight < 556 ) {
        myHeight = 556;
    } else if (myHeight>700) {
        myHeight = 700;
    }

    //get screen size, and cacl center screen positioning
    var height = screen.height;
    var width = screen.width;
    var leftpos = width / 2 - myWidth / 2;
    var toppos = (height / 2 - myHeight / 2) - 40;

    //open window
    msgWindow=window.open(winName,"ws_window","toolbar=no,location=no,directories=no,resizable=yes,menubar=no,scrollbars=no,status=yes,width=" 
                        + myWidth + ",height="+ myHeight + ", left=" 
                        + leftpos + ",top=" + toppos); 

    //focus window
    setTimeout('msgWindow.focus()',1);
}

函数启动(winName){
//窗高和窗宽
myHeight=屏幕高度*.80;
myWidth=784;
//寡妇高度界限
如果(我的身高<556){
我的身高=556;
}否则,如果(我的身高>700){
我的身高=700;
}
//获取屏幕大小和cacl中心屏幕定位
变量高度=屏幕高度;
变量宽度=屏幕宽度;
var leftpos=width/2-myWidth/2;
var-toppos=(身高/2-myHeight/2)-40;
//开窗
msgWindow=window.open(winName,“ws_窗口”,“工具栏=否,位置=否,目录=否,可调整大小=是,菜单栏=否,滚动条=否,状态=是,宽度=”
+myWidth+,height=“+myHeight+”,left=”
+leftpos+”,top=“+toppos);
//焦点窗口
setTimeout('msgWindow.focus()',1);
}

所以我不知道这是否足够,但是,我认为我需要在我想要添加此函数的页面的html编辑器上添加一些代码。我想我需要调用函数和javascript,所以我在页面中添加了以下内容:

<script type="text/javascript" src="/js/wslaunch.js"></script>
<script type="text/javascript">
launchWS();
</script>

launchWS();

我哪里出错了?我应该在页面上以不同的方式调用函数吗?我是否应该包括某些依赖项,或者指定函数应该在function.php文件中排队的单个事件???

您能否具体说明收到的错误?还是什么都没发生?如果您使用的是chrome,右键单击任意位置并选择inspect element以打开开发控制台。从那里点击顶部的“控制台”按钮,看看是否有错误被吐出来。如果是,请将它们粘贴到此处。请从
wsLaunch.js
中删除
,它可能会解决您的问题。以下是发布的错误:加载资源失败:服务器响应状态为404(未找到)未捕获语法错误:意外令牌