![]() |
カレッヂ |
質問者 nac
投稿日 2007/2/28(水) 11:46:57
PHPでスタイルシート切替をしたいのですが、 <?php $thestyle = $_GET['layout']; if ($thestyle == "style1") { $thestyle = "style2"; } else { $thestyle = "style1"; } ?> この場合、1以外は2しか変更することができませんよね? 希望としては、style2,style3,style4...と複数のスタイルシートを切替したいのですが、 この場合、どういう構文になるんでしょうか。
【習熟度】初めて |
回答者 ひろ
[削除]
投稿日 2007/3/2(金) 02:05:28
切替えというのは、次のようなローテーション方式でいいのでしょうか? style2 → style3 → style4 → style1 一例としてswitch 文を使ったものです。 <?php $thestyle = $_GET['layout']; switch ( $thestyle ) { case "style1" : $thestyle = "style2"; break; case "style2" : $thestyle = "style3"; break; case "style3" : $thestyle = "style4"; break; case "style4" : $thestyle = "style1"; break; default : $thestyle = "style1"; } print "<html><body>"; print "今のスタイルは ".$thestyle; print "<br /><a href={$_SERVER['PHP_SELF']}?layout={$thestyle}>次</a>"; print "</body></html>"; ?> |
質問者 nac
[削除]
投稿日 2007/3/2(金) 10:51:53
ひろ さん レスありがとうございました。 教えていた構文でやってみたところ、複数のスタイルシートの切替えができました。 これで理想通りのレイアウトができそうです。 ありがとうございました。 |
このページは終了したので返信(回答)は書きこめません
Web裏技 |