2

I got some html code

<?php 
    if($loggedIn){
       echo "<div id='navigation'>
            <ul>
                <li>
                    <a href='javascript:toggleLayer('video');'>Global</a>
                </li>
                <li>
                    <a href='javascript:toggleLayer('info');'>About</a>
                </li>
                <li>
                    <a href='javascript:toggleLayer('register_main');'>Join!</a>
                </li>
            </ul>
        </div>"};

But when I click on the url's on the website, they happen not to execute the javascript code. after inspectiong one of the elements I found out that

<a video');'="" href="javascript:toggleLayer(">Global</a>

is the code generated, which is wrong ofcourse.

My only clue would be that it should be

     <a href="javascript:toggleLayer('video');">Global</a>

Though i have no clue how to fix that inside the echo, because it has to be in between the if-statement

Thanks in advance!

4

3 回答 3

2

代替:

<?php if($loggedIn){
   echo "<div id='navigation'>
        <ul>
            <li>
                <a href='javascript:toggleLayer('video');'>Global</a>
            </li>
            <li>
                <a href='javascript:toggleLayer('info');'>About</a>
            </li>
            <li>
                <a href='javascript:toggleLayer('register_main');'>Join!</a>
            </li>
        </ul>
    </div>"}; ?>

和:

<?php if($loggedIn){ ?>
    <div id="navigation">
        <ul>
            <li>
                <a href="javascript:toggleLayer('video');">Global</a>
            </li>
            <li>
                <a href="javascript:toggleLayer('info');">About</a>
            </li>
            <li>
                <a href="javascript:toggleLayer('register_main');">Join!</a>
            </li>
        </ul>
    </div>
<?php } ?>

在字符串中使用引号时" I said "Hello" "。您需要转义匹配的周围引号,例如:" I said \"Hello\" "

于 2012-08-29T17:01:51.457 回答
0

尝试这个

...
<a href='javascript:toggleLayer(\"video\");'>Global</a>
...
于 2012-08-29T17:01:31.270 回答
0

问题是你的引号。您必须转义<a>为您的 javascript 函数设置参数的标签内的那些,例如“视频”

于 2012-08-29T17:05:04.857 回答