在jQuery SwitchCase中回显PHP变量? [英] Echo PHP variable inside jQuery SwitchCase?

查看:107
本文介绍了在jQuery SwitchCase中回显PHP变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在包含mt内容并创建facebook/myspace共享链接的PHP页面上包含一个jQuery脚本.我在构建共享URL的swith case语句中回显PHP代码时遇到麻烦.这是我的代码:

案例"facebook": this.href + ='?t ='+ document.title +'& u = http://foobar.com/detail.php?id ='; 休息;

服务器未正确解析PHP代码,而是传递值id=<?php echo "1";?>而不是1.我不能将PHP代码插入javascript include吗?

解决方案

选项1.在您的file.php中:

<script type="text/javascript">
   var varName = "<?php echo '1'; ?>"; // global
</script>
<script type="text/javascript" src="myscript.js"></script>

选项2.创建一个PHP文件,该文件返回javascript内容类型 externalphp

I have a jQuery script that I am including on a PHP page that takes mt content and creates facebook/myspace share links. I am having trouble echoing PHP code inside of the swith case statement that builds the share URL's. Here's my code:

case 'facebook': this.href += '?t=' + document.title + '&u=http://foobar.com/detail.php?id='; break;

The server isn't parsing the PHP code correctly, it's passing the value id=<?php echo "1";?> rather than 1. Can I not insert PHP code into a javascript include?

解决方案

Option 1. In your file.php:

<script type="text/javascript">
   var varName = "<?php echo '1'; ?>"; // global
</script>
<script type="text/javascript" src="myscript.js"></script>

Option 2. create a PHP file that returns the javascript content type externalphp

这篇关于在jQuery SwitchCase中回显PHP变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆