出现在Perl生成的JavaScript代码中的数字而不是“$(" [英] Number appearing in Perl-generated JavaScript code instead of "$("

查看:60
本文介绍了出现在Perl生成的JavaScript代码中的数字而不是“$("的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在研究的网站上,随机数字出现在一个非常简单的jQuery中。

On a site I'm working on there are random numbers appearing in a very simple bit of jQuery.

这些数字 - 48 等 - 出现在开头,而不是出现的意思。像这样:

Instead of what's meant to appear, these numbers — 48, etc. — appear at the beginning. Like this:

<script type="text/javascript">
    48 48document).ready(function () {
    48 48".closed").click(function () {         
        48 48this).find("div.but").toggleClass('plus').toggleClass('minus');           
             48 48this).toggleClass('closed').toggleClass('open');    
        });    
    });        
</script>

我甚至无法想象为什么当我将其硬编码为时它会吐出来该网站,没有外部文件或任何东西。

I can't even begin to imagine why it would spit this out when I hard-coded it into the site and there's no external file or anything.

好的,所以既然它是Perl我需要逃避 $(但是怎么样?我看了一下Perl文档,我觉得自己被打了一拳。

OK, so since it's Perl I need to escape $(, but how? I took a look at the Perl documentation and I just felt like I'd been punched.

我只是用单引号而不是双引号吗? / p>



Do I just use single quotes instead of double quotes?

<script type="text/javascript">
    $(document).ready(function () {
      $('.closed').click(function () {          
        $(this).find('div.but').toggleClass('plus').toggleClass('minus');
        $(this).toggleClass('closed').toggleClass('open');    
      });
  });
</script>

这是完整的Perl脚本。它是网站的标题。

Here's the full Perl script. It's the header of a site.

###########################
## META DATA AND HEADERS ##
###########################

$be_strict = 0;    # 1 = 404 on page not found
if ((!$title{$loadpage} || !$h1{$loadpage} || !$description{$loadpage} || !$keywords{$loadpage} || !$breadcrumb{$loadpage}) && $be_strict) {
  print "Status: 302 Found\r\n" .
      "Location: http://www.realots.co/404/\r\n" .
      "\r\n";
  exit(0);
} 

if ($action) {

  #############################
  ## Highscore page SEO Hack ##
  #############################

  if ($action eq "fish") {
    $breadcrumb{'highscores'}     = "<a href='/'>RealOTS</a> &raquo; <a href='/highscores/'>Highscores</a> &raquo; <b>Fishing Skill</b>";
    $h1{'highscores'}             = "RealOTS Fishing Highscores";
    $title{'highscores'}          = "RealOTS Top Fishing Skill";
    $description{'highscores'}    = "Fishing Skill Highscore list of our RealOTS. Check out these amazing fishermen!";
    $keywords{'highscores'}       = "realots,otserv,tibia,highscore,hiscores,fishing,top fishing";
  }
  elsif ($action eq "ml") {
    $breadcrumb{'highscores'}     = "<a href='/'>RealOTS</a> &raquo; <a href='/highscores/'>Highscores</a> &raquo; <b>Magic Level</b>";
    $h1{'highscores'}             = "RealOTS Magic Highscores";
    $title{'highscores'}          = "RealOTS Top Magic Level";
    $description{'highscores'}    = "Magic Level Highscore list of our RealOTS. Check out these fearsome mages!";
    $keywords{'highscores'}       = "realots,otserv,tibia,highscore,hiscores,magic,top magic";
  }
  elsif ($action eq "sword") {
    $breadcrumb{'highscores'}     = "<a href='/'>RealOTS</a> &raquo; <a href='/highscores/'>Highscores</a> &raquo; <b>Sword Fighting</b>";
    $h1{'highscores'}             = "RealOTS Sword Fighting Highscores";
    $title{'highscores'}          = "RealOTS Top Sword Fighters";
    $description{'highscores'}    = "Sword Fighting Highscore list of our RealOTS. Fear the mighty sword wielder!";
    $keywords{'highscores'}       = "realots,otserv,tibia,highscore,hiscores,sword,top sword";
  }
  elsif ($action eq "axe") {
    $breadcrumb{'highscores'}     = "<a href='/'>RealOTS</a> &raquo; <a href='/highscores/'>Highscores</a> &raquo; <b>Axe Fighting</b>";
    $h1{'highscores'}             = "RealOTS Axe Fighting Highscores";
    $title{'highscores'}          = "RealOTS Top Axe Fighters";
    $description{'highscores'}    = "Axe Fighting Highscore list of our RealOTS. Behold these savage beasts with their amazing axe skills!";
    $keywords{'highscores'}       = "realots,otserv,tibia,highscore,hiscores,axe,top axe,axe fighting";
  }
  elsif ($action eq "club") {
    $breadcrumb{'highscores'}     = "<a href='/'>RealOTS</a> &raquo; <a href='/highscores/'>Highscores</a> &raquo; <b>Club Fighting</b>";
    $h1{'highscores'}             = "RealOTS Club Fighting Highscores";
    $title{'highscores'}          = "RealOTS Top Club Fighters";
    $description{'highscores'}    = "Club Fighting Highscore list of our RealOTS. Caveman-like agility all around!";
    $keywords{'highscores'}       = "realots,otserv,tibia,highscore,hiscores,club,top club,club fighting";
  }
  elsif ($action eq "dist") {
    $breadcrumb{'highscores'}     = "<a href='/'>RealOTS</a> &raquo; <a href='/highscores/'>Highscores</a> &raquo; <b>Distance Fighting</b>";
    $h1{'highscores'}             = "RealOTS Distance Fighting Highscores";
    $title{'highscores'}          = "RealOTS Top Distance Fighters";
    $description{'highscores'}    = "Distance Fighting Highscore list of our RealOTS. Death from afar, raining from the sky!";
    $keywords{'highscores'}       = "realots,otserv,tibia,highscore,hiscores,distance,top distance,distance fighting";
  }
  elsif ($action eq "shield") {
    $breadcrumb{'highscores'}     = "<a href='/'>RealOTS</a> &raquo; <a href='/highscores/'>Highscores</a> &raquo; <b>Shielding</b>";
    $h1{'highscores'}             = "RealOTS Shielding Highscores";
    $title{'highscores'}          = "RealOTS Top Shielding";
    $description{'highscores'}    = "Shielding Highscore list of our RealOTS. These tanks are able to withstand tremendeous blows!";
    $keywords{'highscores'}       = "realots,otserv,tibia,highscore,hiscores,shielding,top shielding";
  }
  elsif ($action eq "fist") {
    $breadcrumb{'highscores'}     = "<a href='/'>RealOTS</a> &raquo; <a href='/highscores/'>Highscores</a> &raquo; <b>Fist Fighting</b>";
    $h1{'highscores'}             = "RealOTS Fist Fighting Highscores";
    $title{'highscores'}          = "RealOTS Top Fist Fighters";
    $description{'highscores'}    = "Fist Fighting Highscore list of our RealOTS. They had special training by sensai Chuck Norris!";
    $keywords{'highscores'}       = "realots,otserv,tibia,highscore,hiscores,fist,top fist,fist fighting";
  }
}

#&print_header();
$web_content .= qq{
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

    <title>$title{$loadpage}</title>
    <meta name="google-site-verification" content="Z97W94Kp7MlIOgiaMAYcFA4Lp4i5hckXdncRarXkBxk" />
    <meta name="google-site-verification" content="I5HTpL8jLRcdrWk3jD83qIFDBkS4G_rmWHlxEq94jLU" />
    <style type="text/css">
      table.outlined {
        border-width: 1px;
        order-style: solid;
        border-color: #9999CC;
        border-collapse: separate;
      }
      a.suggestions:visited{color:#0000FF;text-decoration:none;}
      a.suggestions:link{color:#0000FF;text-decoration:none;}
      a.suggestions:hover{color:#305997;text-decoration:none;}

.trans {
        filter:alpha(opacity=50);
        -moz-opacity:0.5;
        -khtml-opacity: 0.5;
        opacity: 0.5;
}

    </style>
<!--[if IE 6]>
<![endif]-->
<!--[if IE 6]>
<style type="text/css">
html { overflow-y: hidden; }
body { overflow-y: auto; }
img#bg { position:absolute; z-index:-1; }
#content { position:static; }
</style>
<![endif]-->

};

if ($no_index{$loadpage}) {
  $web_content .= qq{    <meta name="Robots" content="NOINDEX,NOFOLLOW,NOARCHIVE,NOSNIPPET" />};
} else {
  $web_content .= qq{    <meta name="Robots" content="index,follow" />};
}

$web_content .= qq{
    <meta name="keywords" content="$keywords{$loadpage}">
    <meta name="description" content="$description{$loadpage}">
    <meta name="author" content="RealOTS" />
    <meta name="Expires" content="never" />
    <link rel="stylesheet" type="text/css" href="/images/style.css" />
    <script type="text/javascript" src="http://www.mollie.nl/partners/js/96481.js"></script>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>


   <script type="text/javascript">
    $(document).ready(function () {
    $(".closed").click(function () {


        $(this).find("div.but").toggleClass('plus').toggleClass('minus');

         $(this).toggleClass('closed').toggleClass('open');

    });

});

    </script>




  </head>
};


推荐答案

$(是一个Perl预定义变量,扩展到进程的组ID列表。

$( is a Perl predefined variable, expanding to the process's group ID list.


如果你在支持成员资格的机器上同时有多个组,给出一个空格分隔的组列表。第一个数字是getgid()返回的数字,后续数字是getgroups(),其中一个可能与第一个数字相同。

If you are on a machine that supports membership in multiple groups simultaneously, gives a space separated list of groups you are in. The first number is the one returned by getgid() , and the subsequent ones by getgroups() , one of which may be the same as the first number.

参见 perlvar 文档了解详情。

为避免此问题,请务必转义 $((和任何其他JavaScript $ 字符)在Perl字符串中,或​​使用''而不是以避免插值。

To avoid the problem, make sure to escape $( (and any other JavaScript $ chars) in Perl strings, or use '' instead of "" to avoid interpolation.

错误:

$html = "$(document).ready(...)";

好:

$html = "\$(document).ready(...)";
$html = '$(document).ready(...)';

在上面的代码中,例如,脚本部分应为:

In the code above, for example, the script section should be:

<script type="text/javascript">
  \$(document).ready(function () {
    \$(".closed").click(function () {

      \$(this).find("div.but").toggleClass('plus').toggleClass('minus');
      \$(this).toggleClass('closed').toggleClass('open');

    });    
  });
</script>

这篇关于出现在Perl生成的JavaScript代码中的数字而不是“$(&quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆