这是我的 JavaScript 函数:
$('.btn-setting').click(function (e) {
e.preventDefault();
$('#myModal').modal('show');
});
这就是我在 PHP 文件中调用它的方式:
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
我的问题是:如何传递变量:
$('#myModal<?php $variable ?>').modal('show');
并在 PHP 文件中调用它,如下所示:
<div class="modal fade" id="myModal<?php echo $variable ;>?" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
最佳答案
在您的 php 文件中,您的脚本中需要 echo 变量,例如
<script>
$('#myModal<?php echo $variable; ?>').modal('show');
</script>
如果你在.js
文件中回显,它不起作用
更新答案
在 php
文件的 html 部分中,您需要 echo variable
如下所示
<div class="modal fade" id="myModal<?=$variable?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
关于javascript - 如何在 Javascript 中编写 PHP 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35556934/