0

谁能指出如何解决我遇到的 2 个语法错误?我对 PHP 不是很先进。

这是代码:

$code = '<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
        <script>
        <table id="slideleft" style=" overflow:auto; position:fixed; top:25%;"><tr class="slideLeftItem" style="position:fixed;left:-320px;z-index:1000;height:100%;"><td><img src="https://lh3.googleusercontent.com/-GMJe-Am-U9Q/T4p4bZu7jDI/AAAAAAAAAFs/qQqmMGn-wwg/s800/facebook-vertical.png" style="top:5px; position:absolute; border-left-width:5px; left:318px;"/></td><td class="contentBox" style="border:solid 5px #5370AD; width:300px;height:300px;position:relative;border-radius:5px;background-color:white;"><div id="fb-root"></div><script type="text/javascript" >(function() {var e = document.createElement('script'); e.async = true;e.src = document.location.protocol +'//connect.facebook.net/en_US/all.js#xfbml=1';document.getElementById('fb-root').appendChild(e);());</script>

       <fb:like-box href="https://www.facebook.com/ExplicitWebsiteDesign?ref=hl" width="300" show_faces="true" stream="false" header="false"></fb:like-box></td></tr></table><script type="text/javascript">jQuery(".slideLeftItem").append('<div style="font-size:12px;font-family: arial;width:300px;text-align:right;"><a rel="dofollow" href="http://techbrij.com/944/add-social-slider-widget-website" style="background-color:#D2C9CA;padding:3px 7px;font-weight:bold;color:#516FA9">Get This Widget</a></div>');jQuery("#slideleft tr").hover(function(b){var a=jQuery(this);jQuery("#slideleft tr").not(a).hide();a.css({"z-index":"9999"});a.stop().animate({left:0})},function(b){var a=jQuery(this);a.css({"z-index":"1000"});a.stop().animate({left:-a.outerWidth()});jQuery("#slideleft tr").show()});</script>}</script>';

下面的图片是我的代码的屏幕截图......谢谢。

在此处输入图像描述

4

2 回答 2

2
$code = ' (function() {var e = document.createElement('scr

您正在尝试将 js 保存为字符串,但 ' 在您的 js 代码中。这搞砸了。你只需要转义那些单引号。将主要内容中的内容从'更改为\'。这应该解决它。

于 2012-12-20T03:36:31.487 回答
2

尝试使用输出缓冲区来发挥您的优势:

ob_start();
?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
        <script>
        <table id="slideleft" style=" overflow:auto; position:fixed; top:25%;"><tr class="slideLeftItem" style="position:fixed;left:-320px;z-index:1000;height:100%;"><td><img src="https://lh3.googleusercontent.com/-GMJe-Am-U9Q/T4p4bZu7jDI/AAAAAAAAAFs/qQqmMGn-wwg/s800/facebook-vertical.png" style="top:5px; position:absolute; border-left-width:5px; left:318px;"/></td><td class="contentBox" style="border:solid 5px #5370AD; width:300px;height:300px;position:relative;border-radius:5px;background-color:white;"><div id="fb-root"></div><script type="text/javascript" >(function() {var e = document.createElement('script'); e.async = true;e.src = document.location.protocol +'//connect.facebook.net/en_US/all.js#xfbml=1';document.getElementById('fb-root').appendChild(e);());</script>

       <fb:like-box href="https://www.facebook.com/ExplicitWebsiteDesign?ref=hl" width="300" show_faces="true" stream="false" header="false"></fb:like-box></td></tr></table><script type="text/javascript">jQuery(".slideLeftItem").append('<div style="font-size:12px;font-family: arial;width:300px;text-align:right;"><a rel="dofollow" href="http://techbrij.com/944/add-social-slider-widget-website" style="background-color:#D2C9CA;padding:3px 7px;font-weight:bold;color:#516FA9">Get This Widget</a></div>');jQuery("#slideleft tr").hover(function(b){var a=jQuery(this);jQuery("#slideleft tr").not(a).hide();a.css({"z-index":"9999"});a.stop().animate({left:0})},function(b){var a=jQuery(this);a.css({"z-index":"1000"});a.stop().animate({left:-a.outerWidth()});jQuery("#slideleft tr").show()});</script>}</script>
<?php
$code = ob_get_clean();
于 2012-12-20T03:41:10.740 回答