thinkphpÖÐÔõôÉèÖÃCSSºÍJavaScript±äÁ¿
Ò»¡¢ÉèÖà CSS ±äÁ¿
1.1 ÔÚ¿ØÖÆÆ÷Öнç˵±äÁ¿
Ê×ÏÈ£¬ÔÚ¿ØÖÆÆ÷Öнç˵ CSS ±äÁ¿¡£¿ÉÒÔͨ¹ýʹÓà $this->assign() º¯Êý½« CSS ±äÁ¿¸³Öµ¸øÄ£°åÎļþ¡£ÀýÈ磺
$this->assign('bg_color', '#ffffff'); // ½« #ffffff ¸³Öµ¸ø $bg_color
µÇ¼ºó¸´ÖÆ
1.2 ÔÚÄ£°åÎļþÖÐʹÓñäÁ¿
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
½ÓÏÂÀ´£¬ÎÒÃÇÐèÒªÔÚÄ£°åÎļþÖÐʹÓñäÁ¿¡£Õâ¿ÉÒÔͨ¹ýʹÓà { $var_name } Óï¾äÀ´ÊµÏÖ¡£ÔÚ±¾ÀýÖУ¬ÎÒÃÇ¿ÉÒÔÔÚ CSS ÎļþÖÐʹÓà $bg_color Åä¾°ÑÕÉ«±äÁ¿£¬ÈçÏÂËùʾ£º
body { background-color: { $bg_color }; }
µÇ¼ºó¸´ÖÆ
1.3 ÔÚÊÓͼÎļþÖÐÊä³ö CSS
×îºó£¬ÎÒÃÇÐèÒªÔÚÊÓͼÎļþÖÐÊä³ö CSS¡£¿ÉÒÔͨ¹ýʹÓà { volist } Óï¾äÀ´ÊµÏÖ¡£ÔÚ±¾ÀýÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏ·½·¨Êä³ö CSS Îļþ£º
<link rel="stylesheet" type="text/css" href="{: url(/help/&) }">
µÇ¼ºó¸´ÖÆ
¶þ¡¢ÉèÖà JavaScript ±äÁ¿
2.1 ÔÚ¿ØÖÆÆ÷Öнç˵±äÁ¿
Ê×ÏÈ£¬ÔÚ¿ØÖÆÆ÷Öнç˵ JavaScript ±äÁ¿¡£¿ÉÒÔͨ¹ýʹÓà $this->assign() º¯Êý½« JavaScript ±äÁ¿¸³Öµ¸øÄ£°åÎļþ¡£ÀýÈ磺
$this->assign('user_id', 1001); // ½« 1001 ¸³Öµ¸ø $user_id
µÇ¼ºó¸´ÖÆ
2.2 ÔÚÄ£°åÎļþÖÐʹÓñäÁ¿
½ÓÏÂÀ´£¬ÎÒÃÇÐèÒªÔÚÄ£°åÎļþÖÐʹÓñäÁ¿¡£¿ÉÒÔͨ¹ýʹÓà { $var_name } Óï¾äÀ´ÊµÏÖ¡£ÔÚ±¾ÀýÖУ¬ÎÒÃÇ¿ÉÒÔÔÚ JavaScript ÎļþÖÐʹÓà $user_id Óû§ ID ±äÁ¿£¬ÈçÏÂËùʾ£º
var userId = { $user_id };
µÇ¼ºó¸´ÖÆ
2.3 ÔÚÊÓͼÎļþÖÐÊä³ö JavaScript
×îºó£¬ÎÒÃÇÐèÒªÔÚÊÓͼÎļþÖÐÊä³ö JavaScript¡£¿ÉÒÔͨ¹ýʹÓà { volist } Óï¾äÀ´ÊµÏÖ¡£ÔÚ±¾ÀýÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏ·½·¨Êä³ö JavaScript Îļþ£º
<script type="text/javascript" src="{: url(/help/&) }"></script>
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇthinkphpÖÐÔõôÉèÖÃCSSºÍJavaScript±äÁ¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡