Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.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
如何在Javascript函数中包含或调用文件_Javascript - Fatal编程技术网

如何在Javascript函数中包含或调用文件

如何在Javascript函数中包含或调用文件,javascript,Javascript,我正在使用下面的代码处理一条成功消息后的弹出窗口。除了一个小问题外,SocialOpup函数工作正常。它应该从三个URL来源(facebook、twitter、google)获取信息,它们的格式是 我试着将源代码放在index.php(主页)文件和header.php(主页头)文件中。header.php使用php include,位于index.php文件中。我将大部分代码和CSS文件保存在header.php文件中,但出于某种原因,它似乎不希望在放置脚本时加载脚本的URL源 所以脚本可以工作

我正在使用下面的代码处理一条成功消息后的弹出窗口。除了一个小问题外,SocialOpup函数工作正常。它应该从三个URL来源(facebook、twitter、google)获取信息,它们的格式是

我试着将
源代码放在index.php(主页)文件和header.php(主页头)文件中。header.php使用php include,位于index.php文件中。我将大部分
代码和CSS文件保存在header.php文件中,但出于某种原因,它似乎不希望在放置脚本时加载脚本的URL源

所以脚本可以工作,但是URL源没有出现,我也不知道如何调用脚本URL源到函数中,以便它们显示在弹出窗口中

我有一个test.html文件,我在其中一起测试了代码,而不是单独测试,并且运行良好。我想可能有一种方法可以用Javascript调用文件,就像PHP include语句一样。尝试
include('somefile.php')位于下面js代码的顶部,但这似乎把一切都搞糟了。有什么想法吗?先谢谢你

jQuery(document).ready(function($) {
    $('form.iform').iform({
    successEnd: function () {        

            $().socialpopup({
                    timeout: 999,
                    title: "Something Clever",
                    message: 'This is great!',
                    google_url: "http://google.com",
                    fb_url: "http://facebook.com",
                    closeable: true,
                    advancedClose: false,
                    opacity: '0.45',
                    twitter_method: "tweet",
                    tweet_url: 'http://twitter.com',
                    tweet_text: 'Just tried out this awesome site - Its Amazing!'

    });

    }
});
更多信息: 谢谢你的回复。作为回应,我发布了更多的代码

以下是header.php的名称

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
    <link rel="stylesheet" type="text/css" href="ifhorm/css/pagestyles.css" /><!-- Page styles -->
    <link rel="stylesheet" type="text/css" href="ifhorm/css/inline.css" /><!-- Standard form layout -->    
    <link rel="shortcut icon" href="favicon.ico" />
    <script src="js/jquery-1.6.3.min.js" type="text/javascript"></script>

下面是我试图包含的链接。

    <link href="socialpopup/socialpopup.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
    <script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
    <script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script>
    <script src="socialpopup/jquery.stp.min.js" type="text/javascript"></script>
</head>

如果我像下面这样在一个HTML文件中使用代码,它的工作方式应该是怎样的,而不是我希望它的工作方式,这就是我在我的网站上放置的表单的成功消息。在HTML文件中,它会在页面打开时弹出。这就是我想要它做的。。。 表单->流程->成功消息->弹出窗口。现在它做了我想做的一切,但不包括我上面调用的脚本URL源

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>

body{
    margin:50px 200px;
}

</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<link href="socialpopup.css" rel="stylesheet" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
<script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script>
<script src="jquery.stp.min.js" type="text/javascript"></script>
<script>

    $(document).ready(function(){          

            $().socialpopup({
                    timeout: 999,
                    title: "Something Clever",
                    message: 'This is great!',
                    google_url: "http://google.com",
                    fb_url: "http://facebook.com",
                    closeable: true,
                    advancedClose: false,
                    opacity: '0.45',
                    twitter_method: "tweet",
                    tweet_url: 'http://twitter.com',
                    tweet_text: 'Just tried out this awesome site - Its Amazing!'
            });

    });


</script>
</head> 

身体{
利润率:50px 200px;
}
无标题文件
$(文档).ready(函数(){
$().socialpopup({
超时:999,
标题:“聪明的东西”,
信息:“这太棒了!”,
谷歌网址:http://google.com",
fb_网址:http://facebook.com",
可接近的:是的,
高级关闭:错误,
不透明度:“0.45”,
twitter_方法:“tweet”,
推特url:'http://twitter.com',
tweet_text:“刚刚试用了这个很棒的网站-太棒了!”
});
});
而且,
好问题。我没有注意到文件已经准备好了两次。我粘贴了另一个文件中的代码,我只是忽略了它,因为它似乎在工作

但是,答案是加载到页面中的所有javascript都位于同一名称空间中。您可以尝试创建代码的一个名称空间吗?为什么要将document ready包装在document ready声明中?谢谢大家。希望这有帮助。