2013-11-22 175 views
0

我是新编码php和javascript。将这个changeContent函数放入我的代码后,它没有找到它。显示参考错误,我认为它与链接中的“//”有关。我将如何去修复它?ReferenceError:函数未定义

<?php 
    $one = "<iframe src='http://www.google.com' width='100%' height='84%'  frameborder='0'></iframe>"; 
    $two = "<iframe src='http://www.facebook.com' width='100%' height='84%' frameborder='0'></iframe>"; 
    $three = "<iframe src='http://www.youtube.com' width='100%' height='84%' frameborder='0'></iframe>"; 
    echo " 
    <html xmlns='http://www.w3.org/1999/xhtml'  xmlns:fb='http://developers.facebook.com/schema/' version='XHTML+RDFa 1.0' xml:lang='en' 
    <head> 

    <link type='text/css' rel='stylesheet' href='style.css'/> 

    <script type='text/javascript'> 
    function changeContent() { 
    document.getElementById('content').innerHTML='<?=$one?>'; 
    } 
    </script> 
    <script type='text/javascript'> 
    function changeContent2() { 
    document.getElementById('content').innerHTML='<iframe src='<?=$two?>' width='100%'     height='84%' frameborder='0'></iframe>'; 
    } 
    </script> 
    <script type='text/javascript'> 
    function changeContent3() { 
    document.getElementById('content').innerHTML='<iframe src='<?$three?>' width='100%'   height='84%' frameborder='0'></iframe></iframe>'; 
    } 
    </script> 
    </head> 

    <body> 

    <div id='topplace'> 
    <ul> 
    <li><a href='#' class='classname' onClick=\"changeContent()\">google <small   class='button'>Test</small></a></li> 
    <li>&nbsp;</li> 
    <li><a href='#' class='classname' onClick=\"changeContent2()\">facebook <small   class='button'>Test</small></a></li> 
    <li>&nbsp;</li> 
    <li><a href='#' class='classname' onClick=\"changeContent3()\">youtube <small class='button'>test</small></a></li> 
    </ul> 
    </div> 

    </body>"; 
    ?> 
+0

你可能会得到一个很大的提示,如果你看看实际生成的HTML页面(如在浏览器中使用View/Source)。 – jfriend00

回答

0

此外,您应该将$one/$two/$three值更改为URL。

而且

.innerHTML='<iframe 

需要改变,以

.innerHTML=\"<iframe 

使JS工作

+0

也需要添加这个谢谢! – Johny

0

由于您使用的字符串concatination,

,所以你不需要用这个withing字符串<?=$one?>

而是写这样$一个或者你可以preffer {$one}

0

回声长字符串不是一个好主意,用include来代替。

<?php 
$one = "<iframe src='http://www.google.com' width='100%' height='84%' frameborder='0'></iframe>"; 
$two = "<iframe src='http://www.facebook.com' width='100%' height='84%' frameborder='0'></iframe>"; 
$three = "<iframe src='http://www.youtube.com' width='100%' height='84%' frameborder='0'></iframe>"; 
include ('view.php'); 

view.php

<html xmlns='http://www.w3.org/1999/xhtml' 
    xmlns:fb='http://developers.facebook.com/schema/' 
    version='XHTML+RDFa 1.0' xml:lang='en'> 

<head> 

<link type='text/css' rel='stylesheet' href='style.css' /> 

<script type='text/javascript'> 
    function changeContent() { 
    document.getElementById('content').innerHTML='<?=addslashes($one)?>'; 
    } 
    </script> 
<script type='text/javascript'> 
    function changeContent2() { 
    document.getElementById('content').innerHTML='<?=addslashes($two)?>'; 
    } 
    </script> 
<script type='text/javascript'> 
    function changeContent3() { 
    document.getElementById('content').innerHTML='<?=addslashes($three)?>'; 
    } 
    </script> 
</head> 

<body> 

    <div id="content"></div> 

    <div id='topplace'> 
     <ul> 
      <li><a href='#' class='classname' onClick="changeContent()">google <small 
        class='button'>Test</small> 
      </a></li> 
      <li>&nbsp;</li> 
      <li><a href='#' class='classname' onClick="changeContent2()">facebook 
        <small class='button'>Test</small> 
      </a></li> 
      <li>&nbsp;</li> 
      <li><a href='#' class='classname' onClick="changeContent3()">youtube 
        <small class='button'>test</small> 
      </a></li> 
     </ul> 
    </div> 

</body></html> 

变化从

'<iframe src='<?=$two?>' width='100%' 

//no <?=, and make change ' to \" 
'<iframe src=\"$two\" width=\"100%\" 

+0

非常感谢你! – Johny

相关问题