完成功能:在文本框中输入1-3中的某一个数字,单击“确定”按钮,跳转到第二个页面second.php。根据输入的数字不同,第二个页面的显示风格不同。如果文本框中填入1:则标题的大小为24pt,颜色为“red”。正文文字颜色为green
我用javascript完成的============ first.html ===========<html><head><title>first.html</title></head><body><form action="second.html" method="get" name="myform"> <input name="csstype" type="text" /> <input name="submit" type="submit" /></form></body></html>============ second.html ==================<html><head><title>second.html</title><style type="text/css">.type1 h1 { color:#f00;}.type1 p { color:#0f0;}.type2 h1 { color:#ffff00;}.type2 p { color:#00ffff;}.type3 h1 { color:#ff00ff;}.type3 p { color:#ff00ff;}</style></head><body><div id="wrap"> <script type="text/javascript" language="javascript">function QueryString(item){ var sValue=location.search.match(new RegExp("[\?\&]"+item+"=([^\&]*)(\&?)","i")) return sValue?sValue[1]:sValue}var csstype=QueryString('csstype');var wrap=document.getElementById("wrap")switch(csstype){ case "2": wrap.className="type2"; break; case "3": wrap.className="type3"; break; default: wrap.className="type1";}</script> <h1>标题</h1> <p>正文正文正文</p></div></body></html>=============================php接受表单post的变量你应该会吧,你可以用php来判断那个总的div用什么class,也可以用javascript(推荐用js)。如果每一种css的项目都很多的话就把那几个类别分成几个CSS文件
first.php:<html><head><title></title></head><body><form action="second.php" method="POST"><input type="text" name="style"/><input type="submit" name="submit" value="提交“/></form></body>second.php:<html><head><link rel="stylesheet" type="text/css" href="<?php if(isset($_POST['style'])) { echo $_POST['style'];} else {echo "default";} ?>.css"><title></title></head><body><h1></h1></body>
直接在你的css属性里面嵌入php语句实现。例如:<?php if($_POST['num']==1) echo 'font-size:24pt;color:red;';?>直接把你的css属性当做echo的输出内容即可。