简体   繁体   English

PHP中的jQuery显示错误

[英]jquery inside php showing errors

I'm trying to insert code into a php page (Wordpress) here is the working model http://jsfiddle.net/Bf49z/13/ 我正在尝试将代码插入php页面(WordPress),这是工作模型http://jsfiddle.net/Bf49z/13/

I get this error 'Parse error: syntax error, unexpected 'pic' (T_STRING), expecting ',' or ';' 我收到此错误“解析错误:语法错误,意外的” pic”(T_STRING),期望为“或”; in /home/raymondp/public_html/wp-content/themes/Child of Chameleon RP/includes/featured.php on line 7' 在/ home / raymondp / public_html / wp-content / themes / Chameleon RP / Childs / Childs / featured.php中的第7行上

In the php page I have 在php页面中

<?php
echo"<script language='javascript'>

<div id="picOne">one</div>
<div id="picTwo">two</div>
<div id="picThree">three</div>
<div id="picFour">four</div>
</script>
";
?>  

 <?php echo "<script type=\"text/javascript\" src=\"www.raymondplumbing.com.au/wp-content/themes/Child of Chameleon RP/plumbers.js\"></script>; ?> 

The css is as per the js fiddle, and is in the stylesheet and verified working. css是根据js小提琴制作的,并且在样式表中并经过验证可以正常工作。 The JS is in the file plumbers.js and looks like this JS位于文件plumbers.js中,如下所示

(function animate(index) {
$elements.eq(index)
    .animate({ opacity: '1', left: '6px' }, 1000)
    .delay(3000)
    .animate({ opacity: '0' }, 1000, function() {
        $(this).css({ left: '400px' });
        animate((index + 1) % $elements.length);
    });
 })(0);

I am a complete beginner at PHP and JS/JQuery although I have been altering/editing php pages for several years. 尽管我几年来一直在更改/编辑php页面,但我是PHP和JS / JQuery的完整初学者。 I know HTML/CSS 我知道HTML / CSS

The code works in the fiddle and I also have it working in an HTML page - but I want it to work in Wordpress where it will run in a box with a background and different words. 该代码可以在小提琴中工作,我也可以在HTML页面中工作-但我希望它在Wordpress中工作,它将在具有背景和不同单词的框中运行。

I'm very lucky to have got this far, with help from here. 我很幸运,在这里得到了帮助,能够走到这一步。 I must be close because I'm getting errors!! 我必须关闭,因为我遇到了错误!

line 7 is the first 第7行是第一行

<div class="pic"> 

Hope someone here can tell me what I've done wrong? 希望有人可以告诉我我做错了什么?

Rob

In PHP you cannot add double quotes inside double quote or you have to escape them. 在PHP中,您不能在双引号内添加双引号,否则必须转义。

change you code from this 从此更改您的代码

<?php
echo"<script language='javascript'>

<div id="picOne">one</div>
<div id="picTwo">two</div>
<div id="picThree">three</div>
<div id="picFour">four</div>
</script>
";
?>

To

This 这个

<?php
echo"<script language='javascript'>

<div id='picOne'>one</div>
<div id='picTwo'>two</div>
<div id='picThree'>three</div>
<div id='picFour'>four</div>
</script>
";
?>  

If you have use Double quotes (") then inside these try to use single quotes or escape them properly. 如果使用双引号(“),则在这些引号内尝试使用单引号或正确转义它们。

In this line of your code you have already escaped quotes with backslashes 在代码的这一行中,您已经用反斜杠转义了引号

<?php echo "<script type=\"text/javascript\" src=\"www.raymondplumbing.com.au/wp-content/themes/Child of Chameleon RP/plumbers.js\"></script>; ?>
<?php
echo"<script language='javascript'>

<div id=\"picOne\">one</div>
<div id=\"picTwo\">two</div>
<div id=\"picThree\">three</div>
<div id=\"picFour\">four</div>
</script>
";
?>  

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

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