0

我的网站有这个问题。我正在尝试让 2 个脚本在同一页面上运行,但除非我删除其中一个,否则其中一个将无法工作:

<script src="js/jquery.op.loc.min.js"></script>

或者

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>

这是我插入页面部分的 javascript 代码:

  <script src="js/jquery.op.loc.min.js"></script>
  <link type="text/css" rel="stylesheet" href="css/jquery.op.loc.min.css" />

   <script>
   jQuery(document).ready(function ($) {
        $("#default-usage .to-lock").loc({
            text: {
                header: "How are you today?",
                message: "Hello!"
            },
            theme: "secrets",
            buttons: {
                order: ["twitter-tweet", "facebook-like", "google-plus"]
            },
            twitter: {
                tweet: {
                    url: "http://twitter.com",
                    text: "tweet!"
                }
            },
            facebook: {
                like: {
                    url: "http://facebook.com"
                },
                appId: "427542137301809"
            },
            google: {
                plus: {
                    url: "http://google.com"
                }
            }
        });
    });
  </script>

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="<?php if($network == "") {echo '';} elseif($network == "") {echo '';} echo $account_id; ?>"></script>
  <script type="text/javascript">
    $(document).ready(function(){
      $("div.process").fadeOut(0);
      $("input.button").click(function() {
        $('div.process div.bar').css("width", "0%");
        $("div.process").fadeOut(0);
        $("span.status span").empty();
        $("span.status span").append("On hold");
        $("span.status").css("color", "#FF0000");
        var urlform = $("input.profile").val();
        $.post("<?php echo $filename; ?>?post=1", {url:urlform}, function(data) {
          var exploded = data.split('||');
          var profileimage = exploded[0];
          var profilename = exploded[1];
          if(profilename !== "") {
            $("img.profileimg").attr("src", profileimage);
            $("span.profilename span").empty();
            $("span.profilename span").append(profilename);
            $("span.status span").empty();
            $("span.status span").append("Searching for account");
            $("span.status").css("color", "#FFFF00");
            $("div.process").fadeIn("2000");
            $('div.process div.bar').animate({
              width: "200px"
            }, 14000, function() {
              $("span.status span").empty();
              $("span.status span").append("Account found");
              $("span.status").css("color", "#33FF00");
              setTimeout(function() {startGateway('<?php echo $widget_id; ?>');}, 500);
            });
          } else {
            $("span.status span").empty();
            $("span.status span").append("Account not found!");
            $("span.status").css("color", "#FF0000");
            $("img.profileimg").attr("src", "img/blank.jpg");
          }
        });
      });
    });
  </script> 

当谈到 javascript 时,我是一个完整的新手,所以任何帮助将不胜感激!

4

1 回答 1

1

您可以尝试做一些事情来使其正常工作。

  1. 确保您的脚本被拉入页面,一种检查方法是使用 Chrome 调试器中的“源”选项卡并在 html 头部分中搜索其他文件

  2. 确保在包含 jQuery 之后包含了其他脚本,因为它肯定依赖于它。

  3. 检查是否正确包含 jQuery,并且只包含一次。

  4. 注意 jQuery 冲突。还有一些其他库覆盖了 $,因此您的代码无法正常工作,因为 $ 不再是 jQuery 的别名。您可以使用它jQuery.noConflict()来避免与页面上使用相同变量 $ 的其他库发生冲突。

于 2013-04-19T04:57:01.920 回答