0

我正在尝试在 javascript 函数中检索页面内容。当我回显测试变量$htmlblock时,javascript 灯箱完美运行。但是当我 echo 时$contactinfo,它会在新选项卡中打开页面。

<?php  
    // retireve content from "contact" page
    $contactpageid=85;
    $contactpage = get_page($contactpageid);
    $contactinfo = apply_filters('the_content', $contactpage->post_content);
    //test variable
    $htmlblock = '<strong>Contact Information</strong><br/><table><tr><td id="name"><strong>NAME</strong></td><td id="phone"><a href="tel:+18888888888">888-8888</a></td><td id="email"><a href="mailto:name@email.com" target="_blank">name@email.com</a></td></tr></table>';
?>


<script language="javascript" type="text/javascript">
    function openLightbox() {
        lightbox('<?php echo $contactinfo; ?>');
    }
</script>
4

1 回答 1

0

$contactinfo可能包含 HTML 标签,其中 as$htmlblock只是一个简单的字符串。

我不确定你可以用那个灯箱做到这一点。您可能需要查看 Lightbox 文档(您使用的版本),了解如何插入 HTML 内容。

或者,您可以尝试剥离 HTML。

$contactinfo = apply_filters('the_content', strip_tags($contactpage->post_content));

http://php.net/manual/en/function.strip-tags.php

于 2013-09-13T16:57:44.613 回答