需要有关此脚本的一些帮助
(function($) {
var oldHide = $.fn.popover.Constructor.prototype.hide;
$.fn.popover.Constructor.prototype.hide = function() {
if (this.options.trigger === "hover" && this.tip().is(":hover")) {
var that = this;
// try again after what would have been the delay
setTimeout(function() {
return that.hide.call(that, arguments);
}, that.options.delay.hide);
return;
}
oldHide.call(this, arguments);
};
})(jQuery);
$(document).ready(function () {
$('#example').popover({
html: true,
trigger: 'hover',
container: '#example',
placement: 'bottom',
content: function () {
return '<div class="box">here is some content</div>';
},
animation: false,
delay: {
hide: 1500
}
}).on({
show: function () {
console.log("shown");
},
hide: function () {
console.log("hidden");
}
});
});
这是一个引导弹出窗口,我想要的只是在其中添加一个 php 脚本
<div class=box><?php php_here(); ?></div>
因为我需要输出一个wordpress脚本
<?php wp_nav_menu(); ?>
这可能吗?
最佳答案
只要您尝试写入 php 的文件是 .php
文件,或者服务器像处理该文件一样处理它,您就可以在其中写入 php。
如果这是 .js
文件,您可能必须将其设为 .php
文件,服务器才能正确处理它。但除此之外,它应该按照您想要的方式工作(有一些方法可以让服务器将 javascript 文件处理为 php 文件,但这可能不是最好的主意,而且它比仅仅重命名 js 文件要多一些工作)。
如果将其更改为 .php
文件,您将需要向客户端发送类型为 application/javascript
的内容类型 header 才能正确处理。
示例:
test.php
<?php header('Content-Type: application/javascript'); ?>
alert('This is a .php file with javascript in it!');
index.html
<script src="test.php"></script>
//Should show an alert with "This is a .php file with javascript in it!" when opening index.html
编辑:添加示例
关于javascript - 如何在javascript中添加php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20727611/