【问题标题】:Execute a Jquery file from PHP从 PHP 执行 Jquery 文件
【发布时间】: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 '&lt;script src="fixTableHeaders.js"&gt;&lt;/script&gt;';... ?

标签: php jquery html css


【解决方案1】:

Javascript 代码在链接到 html 页面时执行。所以你可以直接回显

【讨论】:

    【解决方案2】:

    只需回显脚本调用。

    echo "<script src='/myscript.js'></script>"; // comment to make a valid edit
    

    【讨论】:

      猜你喜欢
      • 2016-09-24
      • 1970-01-01
      • 1970-01-01
      • 2019-02-19
      • 2016-09-24
      • 2015-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多