jquery基于user_id的动态href
我已经输入了这个小 Jquery 来根据用户 ID 动态附加我的计费页面的 href。
它似乎不起作用?希望有人能指出我的错误。
预先感谢您的帮助和代码片段。
$individualpage="billing".$_SESSION['user_id'].".php";
$("a#billing").attr("href", "$individualpage");
页面上有链接
<a href="" id="billing">billing</a>
I have typed up this little Jquery to dynamically append the href of my billing page based on the users id.
It doesn't seem to be working tho? Hopefully someone can point out my mistake.
Thanks in advance for your help and code snippets.
$individualpage="billing".$_SESSION['user_id'].".php";
$("a#billing").attr("href", "$individualpage");
Link on page
<a href="" id="billing">billing</a>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将 JavaScript(一种客户端语言)与 PHP(一种服务器端语言)混合在一起。请记住,PHP 是在 JavaScript 开始时就完成的。
,请尝试如下操作:
PHP 页面中的某处:
然后,在页面的 HTML 中,使用 PHP 将值转储到 JavaScript,以便它可以拾取并完成请求:
话虽如此 ,您最好直接将其转储到
标记中:(
并且完全跳过 JavaScript。)
You're mixing JavaScript (a client-side language) with PHP (a server-side language). Remember that PHP is done by the time JavaScript begins.
With that said, try something like this:
Somewhere in your PHP page:
Then, within the HTML of the page, use PHP to dump the value to JavaScript so it can pick up and complete the request:
Although, you're probably better off just dumping it directly in to the
<a>
tag:(And skipping JavaScript altogether.)
您可能将 PHP 和 JS 代码混合在一起。
您需要
在视图脚本中。
Your probably mixing PHP and JS code together.
You need
in your view script.