ReferenceError:未定义函数

时间:2013-11-22 07:01:09

标签: javascript php

我是编码php和javascript的新手。将此changeContent函数放入我的代码后,它找不到它。显示引用错误,我认为它与链接中的“//”有关。我该怎么办呢?

    <?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>";
    ?>

3 个答案:

答案 0 :(得分:0)

由于您正在使用字符串连接,

因此您无需使用此字符串<?=$one?>

而是用这种方式写一个或者你可以选择{$one}

答案 1 :(得分:0)

echo long string不是一个好主意,请改用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%\"

<击>

答案 2 :(得分:0)

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

并且

 .innerHTML='<iframe

需要更改为

 .innerHTML=\"<iframe

使JS工作