javascript 在 jQuery 中执行 PHP 代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26149412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 05:34:45  来源:igfitidea点击:

Execute a PHP code inside jQuery

javascriptphpjquery

提问by Mia

That's what I have:

这就是我所拥有的:

<a href="<?=$arItem["LINK"]?>#nav-link">LinkName</a>

Here <?=$arItem["LINK"]?>I'm getting some link, and I want to add to the end of this link some extra hashtag parameter #nav-link.

在这里,<?=$arItem["LINK"]?>我得到了一些链接,我想在此链接的末尾添加一些额外的主题标签参数#nav-link

But the main problem is that PHP is executing on the server side, so, when I click the link, I get only link from the <?=$arItem["LINK"]?>(blabla.com). After second click, I have necessary code blabla.com/#nav-link.

但主要问题是 PHP 在服务器端执行,因此,当我单击链接时,我只能从<?=$arItem["LINK"]?>(blabla.com)获得链接。第二次点击后,我有必要的代码blabla.com/#nav-link

So, is it possible to get blabla.com/#nav-linkafter first click?

那么,是否有可能blabla.com/#nav-link在第一次点击后获得?

回答by Mr. Concolato

Try something to the tune of this:

尝试一些与此相关的内容:

<script>
  var data = <?php echo $arItem["LINK"]; ?>

  var yourLink = "blabla.com/"+data;

  //more of your code etc....

  $('#yourDiv_where_you_want_the_link').html(yourLink);

 </script>