Posts Tagged ‘个页’

同一个页面用多个id有什么影响

星期三, 06月 4th, 2008

我知道在样式表定义一个样式de时候,可以定义id也可以定义class,例如:

ID方法:#test{color:#333333},在页面中调用内容


CLASS方法:.test{color:#333333},在页面中调用内容
id一个页面只可以使用一次,class可以多次引用.

有网友问,id和class好象没什么区别,我在页面中用了多个id在IE中显示也正常,用多个id有什么影响吗?

回答:第一影响就是不能通过W3de校验.

在页面显示上,目前de浏览器还都允许您犯这个错误,用多个相同ID“一般情况下”也能正常显示.但是当您需要用JavaScript通过id来控制这个div,那就会出现错误.

id是一个标签,用于区分不同de结构和内容,就象您de名字,如果一个屋子有2个人同名,就会出现混淆;
class是一个样式,可以套在任何结构和内容上,就象一件衣服;
概念上说就是不一样de:
id是先找到结构/内容,再给它定义样式;class是先定义好一种样式,再套给多个结构/内容.

web标准希望大家用严格de习惯来写相关代码,

例如:您可以用显示粗体,也可以用来显示,但W3C 建议大家用,因为更有语义

如果对这些细节问题不重视,觉得无所谓,
那么您就没必要向xml过渡了,也没必要学习web标准了,因为web标准应用就是从这些小细节上de改变开始,否则用现在dehtml不是也可以?

动态CSS站点教程:多个页面样式提供浏览者选择

星期三, 06月 4th, 2008

在cnbruce’’s blog上看到这个即时换STYLEde相关代码,觉得不错就COPY过来备用.
在见de例子就是:一个站点上有多个页面样式提供浏览者选择.同时,在选择了某样式后,再次打开该页面时,将仍然保持该样式.自然会想到了Cookie技术.


程序相关代码
<HTML>
<HEAD>
<link ID=”skin” rel=”stylesheet” type=”text/css”>
<TITLE>换肤技术</TITLE>
<SCRIPT LANGUAGE=javascript>
<!–
function SetCookie(name,value){
var argv=SetCookie.arguments;
var argc=SetCookie.arguments.length;
var expires=(2<argc)?argv[2]:null;
var path=(3<argc)?argv[3]:null;
var domain=(4<argc)?argv[4]:null;
var secure=(5<argc)?argv[5]:false;
document.cookie=name “=” escape(value) ((expires==null)?”":(”; expires=” expires.toGMTString())) ((path==null)?”":(”; path=” path)) ((domain==null)?”":(”; domain=” domain)) ((secure==true)?”; secure”:”");
}

function GetCookie(Name) {
var search = Name “=”;
var returnvalue = “”;
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search);
if (offset != -1) {
offset = search.length;
end = document.cookie.indexOf(”;”, offset);
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset,end));
}
}
return returnvalue;
}

var thisskin;
thisskin=GetCookie(”nowskin”);
if(thisskin!=”")
skin.href=thisskin;
else
skin.href=”css.css”;

function changecss(url){
if(url!=”"){
skin.href=url;
var expdate=new Date();
expdate.setTime(expdate.getTime() (24*60*60*1000*30));
//expdate=null;
//以下设置COOKIES时间为1年,自己随便设置该时间..
SetCookie(”nowskin”,url,expdate,”/”,null,false);
}
}
//–>
</SCRIPT>
</HEAD>
<BODY>

<P>请选择下面de下拉菜单测试换肤效果</P>

<a href=# onclick=”changecss(”css.css”)”>css.css</a>
<a href=# onclick=”changecss(”css1.css”)”>css1.css</a>
<a href=# onclick=”changecss(”css2.css”)”>css2.css</a>
<a href=# onclick=”changecss(”css3.css”)”>css3.css</a>
<br>

<select onchange=”changecss(this.value)”>
<option>选择样式单文件</option>
<script language=”javascript”>
var csss=new Array();
csss[0]=”css.css”;
csss[1]=”css1.css”;
csss[2]=”css2.css”;
csss[3]=”css3.css”;
var i;
for(i=0;i<4;i )
if(thisskin==csss[i])
document.write(”<option value=\”" csss[i] “\” selected>” csss[i] “样式单文件</option>”);
else
document.write(”<option value=\”" csss[i] “\”>” csss[i] “样式单文件</option>”);
</script>
</select>
</BODY>
</HTML>

2个页面间不通过Session与url的传值方式

星期二, 06月 3rd, 2008

下面是全部相关代码,已经编译通过.
Chuandi(传递)是名字空间

WebForm1:
<%@ Page language=”c#” Codebehind=”WebForm1.aspx.cs” Inherits=”chuandi.WebForm1″ %>
<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
<body>
<form id=”Form1″ method=”post” runat=”server”>
<asp:TextBox id=”TextBox1″ runat=”server”></asp:TextBox>
<asp:Button id=”Button1″ runat=”server” Text=”传”></asp:Button>
</form>
</body>
</HTML>
using System;
namespace chuandi
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;
public string Text1
{
get
{
return this.TextBox1.Text;
}
}
private void Page_Load(object sender, System.EventArgs e)
{}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Button1.Click = new System.EventHandler(this.Button1_Click);
this.Load = new System.EventHandler(this.Page_Load);
}
private void Button1_Click(object sender, System.EventArgs e)
{
Server.Transfer(”WebForm2.aspx”);
}
}
}


WebForm2:
<%@ Page language=”c#” Codebehind=”WebForm2.aspx.cs” Inherits=”chuandi.WebForm2″ %>
<%@ Reference Page=”WebForm1.aspx” %>
<HTML>
<HEAD>
<title>WebForm2</title>
</HEAD>
<body>
<form id=”Form1″ method=”post” runat=”server”>
<asp:Label id=”Label1″ runat=”server”>Label</asp:Label>
<asp:Button id=”Button1″ runat=”server” Text=”返回”></asp:Button>
</form>
</body>
</HTML>
using System;
namespace chuandi
{
public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label1;
public chuandi.WebForm1 wf1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
wf1=(chuandi.WebForm1)Context.Handler;
Label1.Text=”上页传来de是:” wf1.Text1;
}
}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Button1.Click = new System.EventHandler(this.Button1_Click);
this.Load = new System.EventHandler(this.Page_Load);
}
private void Button1_Click(object sender, System.EventArgs e)
{
Server.Transfer(”WebForm1.aspx”);
}
}

多数据表共用一个页的新闻发布

星期一, 06月 2nd, 2008

本文为了简单并能够说明主要内容,一些次要dehtml内容相对简单.
在网站有多个内容要在某一页显示时可在网页中共用一个显示和提交.
本例中有两个数据表(news,ctm);一个主页(index.php);
一个提交页(index_pub.php;和一个包函页(index_view.php)
一个子页(view_d.php).
—-news,ctm—
increate table news(id int(80) not null auto_increment,title char(100),detail text,primay key(id));
increate table ctm(id int(80) not null auto_increment,title char(100),detail text,primay key(id));

—-index_view.php—
<?ph
$query="select * from ".$name." order by id desc limit 0,5;
$result=mysql_query($query,$db);
if ($result){
while($myrow=msyql_fetch_array($result)){
?>
<tr><td><a href="view_d.php?recod=<?php echo $myrow[id]; ?>&name=<?php echo $name; ?>">$myrow[title]</a></td></tr>
<?php
}
}
else{
echo "这里还没新de内容.";}
?>

—-index.php—
<?php
$id=mysql_connect("localhost","username","password");
$db=mysql_select_db("your_db",$id);
?>
<html>
<body>
<hr size=0 color=green width=100%>
<p align=left><font color=green size= 3>Yourname Online</font></p>
<hr size=3 color=green width=100%>
<p align=left><font size=-1>您现在de位置–>首页</font></p>
<hr size=2 color=green width=100%>
<table width=100 border=0 cellpadding=0 cellspacing=0>
<tr>
<!– news –>
<td width=50% align=left>
<table width=100 border=0 cellpadding=0 cellspacing=0>
<?php
$name=news;
include("index_view.php");
?>
</table>
</td>
<!– ctm –>
<td width=50% align=left>
<table width=100 border=0 cellpadding=0 cellspacing=0>
<?php
$name=ctm;
include("index_view.php");
?>
</table>
</td>
</tr>
</table>
<hr size=0 width=100% color=green>
<p align=center><font size=-1>Copyrignt 1999…</font></P>
</body>
</html>
—-index_pub.php—
<?php
$id=mysql_connect("localhost","username","password");
$db=mysql_select_db("your_db",$id);
?>
<html>
<body>
<form action=index_view.php method=post>
<p>请选择数据库:<br>
<select name=db_name size=1>
<option value=news>news</option>
<option value=ctm>ctm</option>
</select></p>
<p>标题:<br>
<input type=text name=title size=20></p>
<p>内容:<br>
<textarea rows=6 cols=10 name=detail></textarea></p>
<p><input type=submit value=submit></p>
</form>
<?php
switch ($db_name){
case news:$name=news;
break;
case ctm:$name=ctm;
break;
}
$query="insert into ".$name."(title,detail) values(’$title’,'$detail’);
$result=mysql_query($query,$db);
if ($result){echo "ok";}
else{echo "failed";}
?>
</body>
</html>
—-view_d.php—
<?php
$id=mysql_connect("localhost","username","password");
$db=mysql_select_db("your_db",$id);
?>
<html>
<body>
<?php
if ($recod){
$query="select * from ".$name." where id=".$recod;
$result=mysql_query($query,$db);
$title=mysql_result($result,0,title);
$detail=mysql_result($result,0,detail);
echo "<p>标题:".$title."</p>";
echo "<p>内容:".$detail."</p>";
}
else{echo "此文件已被删除!";}
</body>
</html>