如何将PHP代码放入javascript中?

时间:2014-05-01 17:27:17

标签: javascript php wordpress

请在下面的脚本下面找到...

我想在url变量上插入一个链接!

<script type="text/javascript">
jQuery.noConflict();                    
jQuery(document).ready(function ($) {
    $(".to-lock-1").sociallocker({
        text: {
            header: "<center>The content is locked!</center>",
            message: "<center></br>Please support us, click like button below to download the Wallpaper.</center>"
        },

        theme: "starter",

        locker: {
            close: false,
            timer: 0
        },

        buttons: {                                
            order: ["facebook-like", "twitter-tweet", "twitter-follow", "google-plus", "linkedin-share"]
        },

        facebook: {  
            appId: "206841902768508",
            like: {
                title: "Like us",
                url: "https://www.facebook.com/9H9Gang"
            }
        },

        twitter: {
            tweet: {
                title: "Tweet",
                text: "PHPGang Programming Blog, Tutorials, jQuery, Ajax, PHP, MySQL and Demos.",
                URL: "http://www.phpgang.com/"
            },
            follow: {
                title: "Follow us",
                url: "http://twitter.com/phpgang"
            }
        },

        google: {                                
            plus: {
                title: "Plus +1",
                url: "http://www.phpgang.com/"
            }
        },

        linkedin: {
            url: "http://www.phpgang.com/",                                
            share: {
                title: "Share"
            }
        }
    });
});

我想更改网址:&#34; http://www.phpgang.com/ URL: "<?php the_permalink(); ?>

我正在使用此脚本锁定我的wordpress博客上的部分内容!`

        twitter: {
        tweet: {
            title: "Tweet",
            text: "PHPGang Programming Blog, Tutorials, jQuery, Ajax, PHP, MySQL and Demos.",
            URL: "http://www.phpgang.com/"
        },
        follow: {
            title: "Follow us",
            url: "http://twitter.com/phpgang"
        }
    }

1 个答案:

答案 0 :(得分:0)

<?php $htmlString= 'testing'; ?>
<html>
  <body>
    <script type="text/javascript">  
      // notice the quotes around the ?php tag         
      var htmlString="<?php echo $htmlString; ?>"; //put your code here
      alert(htmlString);
    </script>
  </body>
</html>

试试这个。这是一个简单的例子......谢谢