php 動態載入JavaScript或css檔案的方法

來源:互聯網
上載者:User
複製代碼

test6.php

  1. header('Content-Type: application/x-javascript; charset=UTF-8');
  2. $str = $_GET["str"];
  3. ?>
  4. // javascript document
  5. // by bbs.it-home.org
  6. alert('');
  7. function tester(string)
  8. {
  9. string ? alert(string) : alert('you call a function named tester');
  10. }
  11. ?>
複製代碼

第二種方法:test.php

複製代碼

test5.php

  1. var value="this is value.";
複製代碼

載入多JavaScript檔案的執行個體:

  1. var url = [
  2. 'ajax.php?ajax=1',
  3. 'functions.js'
  4. ];
  5. loadmultijs(url,function(){ alert("載入完畢。"); /* 這裡可以調用動態載入的JS檔案的資料或方法 */ });
複製代碼

2. 動態載入css檔案test.php

  1. this document has a #e4e4e4 background, a 300px/400px div, and a arial/24px/red words.
複製代碼

div.php

  1. // declare the output of the file as CSS
  2. header('Content-type: text/css');
  3. // include the script
  4. //include('others.php');
  5. $width = $_GET['w'];
  6. $height = $_GET['h'];
  7. ?>
複製代碼
  1. div{width:px;height:px;border:blue 1px solid;}
複製代碼

fonts.php

  1. // declare the output of the file as CSS
  2. header('Content-type: text/css');
  3. // include the script
  4. //include('others.php');
  5. $size = $_GET['s'];
  6. $color = $_GET['c'];
  7. ?>
  8. body{font-family:arial;font-size:px;color:}
複製代碼

就是這些了,php動態載入js與css的方法就介紹完了,建議大家親自動手測試下,看看具體的實現有沒有問題。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.