从HTML转移到PHP时jQuery没有响应?

时间:2011-02-21 11:58:00

标签: php jquery html

Venkman调试器说:

    $("#aboutbox") is null
[Break On This Error] $("#aboutbox").hide(); 

但我不知道该怎么做才能解决它! 它在HTML中完美运行:http://leventhan.webfactional.com/static/ 但是当我把它移到PHP时,它就停止了工作。

这是index.php:

    <?php

require_once dirname(__FILE__)."/src/phpfreechat.class.php";
$params = array();
$params["title"] = "Quick chat";
$params["nick"] = "guest".rand(1,1000);  // setup the intitial nickname
$params['firstisadmin'] = true;
//$params["isadmin"] = true; // makes everybody admin: do not use it on production servers ;)
$params["serverid"] = md5(__FILE__); // calculate a unique id for this chat
$params["debug"] = false;
$chat = new phpFreeChat( $params );

?>
<!DOCTYPE html>
<html>
 <head>
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <title>phpFreeChat- Sources Index</title>
  <link rel="stylesheet" title="classic" type="text/css" href="style/styles.css" />
  <link rel="stylesheet" title="classic" type="text/css" href="style/content.css" />  
  <script type="text/javascript"src="http://maps.google.com/maps/api/js?sensor=false"></script>
  <script type="text/javascript" src="jquery-1.4.4.min.js"></script>
  <SCRIPT type="text/javascript" src="oracle.js"></SCRIPT>

<script type="text/javascript">
 // some google maps javascript code that works fine
 </script>
 </head>
 <body>

<header>
    <div id="aboutbox">
    <br>
    <p><strong>GeoChat is the perfect chat app to hatch your world domination plans. A place on the web where you can point to maps and chat at the same time. 
    A great way for teachers to teach and students to learn with an interactive map. </strong></p>
    </div>
    <div id ="nav">
        <h1>GeoChat</h1><h2><a href="#" id="changebg">Toggle background</a><a href="#" id="toggle">Chat Help</a><a href="#" id="about">What's all this about?</a></h2>
    </div>
    </header>

    <div id="map_canvas"></div>

<div class="content">
  <?php $chat->printChat(); ?>
  <?php if (isset($params["isadmin"]) && $params["isadmin"]) { ?>
  <?php } ?>
</div>

        <footer>
            <p>&#10084 Made by <strong><a href="http://cloudborn.me" id="name">Author</a></strong> with love.<a href="javascript:#" id="dirbutton">Go up &#8593</a></p>
        </footer>

</body></html>

这是现场破损的网站:http://leventhan.webfactional.com/phpfreechat-1.3/


编辑:是的,当我评论出聊天应用程序(phpFreeChat)时,jQuery再次工作,这一部分:

<div class="content">
  <?php $chat->printChat(); ?>
  <?php if (isset($params["isadmin"]) && $params["isadmin"]) { ?>
  <?php } ?>
</div>

事实证明问题实际上是因为jQuery与Prototype.js冲突(phpFreeChat显然使用Prototype。)解决方案是使用:

jQuery.noConflict();

3 个答案:

答案 0 :(得分:1)

编辑:哦,这实际上是你的静态版本,所以静态版本似乎被打破了。鉴于此,不可能分辨出PHP版本中的不起作用。

我收到错误

  

oracle.js:4未捕获的ReferenceError:未定义隐藏

引发错误的行是

 $("#aboutbox").live(hide()); 

也许你的意思是$("#aboutbox").hide();

答案 1 :(得分:1)

有效! 这是jQuery和Prototype彼此不相处。

这就是我的所作所为:

  1. 添加:

    jQuery.noConflict();
  2. 更改所有出现的内容:

    (文档)$。就绪(函数(){ 至: jQuery(document).ready(function($){

  3. 在我的外部js中进行查找和替换。

    找到:$ replace:jQuery(区分大小写)。

答案 2 :(得分:0)

我在这里看到错误(Chrome)

function showInDiv(text)
{
    var sidediv = document.getElementById('content_window');
    sidediv.innerHTML = text; // Cannot set property 'innerHTML' of null
}

什么是content_window?我在页面上找不到它