【发布时间】:2015-09-29 18:41:29
【问题描述】:
我有一个 .Js 文件,我想调用它在 php 代码中执行以修复表头,我不知道如何从 PHP 调用函数。
这是我的 PHP 代码:
echo "<div class=\"wrapper\">";
echo "<table class=\"blue\"><thead><tr><th>ITS No</th><th>Date</th> <th>Cell</th><th>Shift</th><th>Requestor</th><th>Category</th><th>Issue</th>";
echo "<th>Action</th><th>Action Owner</th><th>Aging</th><th>Status</th><th>Comments</th><th>Completed Date</th></tr></thead><tbody>";
我创建了表头,然后我想使用 jquery 函数来修改和修复表头
JS代码:
(function($) {
$.fn.fixMe = function() {
return this.each(function() {
var $this = $(this),
$t_fixed;
function init() {
$this.wrap('<div class="container" />');
$t_fixed = $this.clone();
$t_fixed.find("tbody").remove().end().addClass("fixed").insertBefore($this);
resizeFixed();
}
function resizeFixed() {
$t_fixed.find("th").each(function(index) {
$(this).css("width", $this.find("th").eq(index).outerWidth() + "px");
});
}
function scrollFixed() {
var offset = $(this).scrollTop(),
tableOffsetTop = $this.offset().top,
tableOffsetBottom = tableOffsetTop + $this.height() - $this.find("thead").height();
if (offset < tableOffsetTop || offset > tableOffsetBottom)
$t_fixed.hide();
else if (offset >= tableOffsetTop && offset <= tableOffsetBottom && $t_fixed.is(":hidden"))
$t_fixed.show();
}
$(window).resize(resizeFixed);
$(window).scroll(scrollFixed);
init();
});
};
})(jQuery);
$(document).ready(function() {
$("table").fixMe();
$(".up").click(function() {
$('html, body').animate({
scrollTop: 0
}, 2000);
});
});
【问题讨论】:
-
echo '<script src="fixTableHeaders.js"></script>';... ?