2006-11-02

前段写过一篇更人性化的交互表单表现形式,今天再来推荐一款更具亲和力的表单结构。其好处在于:1.标签语义化增强。2.用户体验更好。

好处1的解释:充分运用xhtml固有标签label,将“用户名”、“密码”、“重复密码”等字符放进label标签里,令其具备语义。

好处2的解释:给label赋予for属性,并给后面的input赋予相同的id,用户在点击label里的文字时,对应的input被激活,变得可输入。

废话少说,代码贴上:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Form demo</title>
<style type="text/css">
<!--
body {
 font-family: Arial, Helvetica, sans-serif;
 font-size:12px;
 color:#666666;
 background:#fff;
 text-align:center;

}

* {
 margin:0;
 padding:0;
}

a {
 color:#1E7ACE;
 text-decoration:none; 
}

a:hover {
 color:#000;
 text-decoration:underline;
}
h3 {
 font-size:14px;
 font-weight:bold;
}

pre,p {
 color:#1E7ACE;
 margin:4px;
}
input, select,textarea {
 padding:1px;
 margin:2px;
 font-size:11px;
}
.buttom{
 padding:1px 10px;
 font-size:12px;
 border:1px #1E7ACE solid;
 background:#D0F0FF;
}
#formwrapper {
 width:450px;
 margin:15px auto;
 padding:20px;
 text-align:left;
 border:1px solid #A4CDF2;
}

fieldset {
 padding:10px;
 margin-top:5px;
 border:1px solid #A4CDF2;
 background:#fff;
}

fieldset legend {
 color:#1E7ACE;
 font-weight:bold;
 padding:3px 20px 3px 20px;
 border:1px solid #A4CDF2; 
 background:#fff;
}

fieldset label {
 float:left;
 width:120px;
 text-align:right;
 padding:4px;
 margin:1px;
}

fieldset div {
 clear:left;
 margin-bottom:2px;
}

.enter{ text-align:center;}
.clear {
 clear:both;
}

-->
</style>
</head>

<body>
<div id="formwrapper">

<h3>已注册用户登录</h3>
 <form action="" method="post" name="apLogin" id="apLogin">
 <fieldset>
  <legend>用户登录</legend>
  <div>
   <label for="Name">用户名</label>
   <input type="text" name="Name" id="Name" size="18" maxlength="30" /><br />
  </div>
  <div>
   <label for="password">密码</label>
   <input type="password" name="password" id="password" size="18" maxlength="15" /><br />
  </div>
  <div class="cookiechk">
   <label><input type="checkbox" name="CookieYN" id="CookieYN" value="1" /> <a href="#" title="选择是否记录您的信息">记住我</a></label>
   <input name="login791" type="submit" class="buttom" value="登录" />
  </div> 
  <div class="forgotpass"><a href="#">您忘记密码?</a></div> 
 </fieldset>
 </form><br />
 <h3>未注册创建帐户</h3>
 <form action="" method="post" name="apForm" id="apForm">
 <fieldset>
  <legend>用户注册</legend>
  <p><strong>您的电子邮箱不会被公布出去,但是必须填写.</strong> 在您注册之前请先认真阅读服务条款.</p>
  <div>
  <label for="Name">用户名</label>
  <input type="text" name="Name" id="Name" value="" size="20" maxlength="30" />
  *(最多30个字符)<br /> 
 </div>
  <div>
  <label for="Email">电子邮箱</label>
  <input type="text" name="Email" id="Email" value="" size="20" maxlength="150" /> *<br /> 
 </div> 
  <div>
  <label for="password">密码</label>
  <input type="password" name="password" id="password" size="18" maxlength="15" />
  *(最多15个字符)<br />
 </div>
  <div>
  <label for="confirm_password">重复密码</label>
  <input type="password" name="confirm_password" id="confirm_password" size="18" maxlength="15" />
  *<br />

 </div>
  <div>
  <label for="AgreeToTerms">同意服务条款</label>
      <input type="checkbox" name="AgreeToTerms" id="AgreeToTerms" value="1" />
      <a href="#" title="您是否同意服务条款">先看看条款?</a> * </div>  
  <div class="enter">
     <input name="create791" type="submit" class="buttom" value="提交" />
     <input name="Submit" type="reset" class="buttom" value="重置" />
 </div>

  <p><strong>* 在提交您的注册信息时, 我们认为您已经同意了我们的服务条款.<br />
     * 这些条款可能在未经您同意的时候进行修改.</strong></p> 
 </fieldset>
 </form>
</div>
</body>
</html>

2006-09-18

本想来一例CSS耍宝二,看到这个js效果实在很酷,忍不住要拿出来与大家分享:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN">
<title>用层模拟的小窗口(可拖动展合)</title>
<meta http-equiv=Content-Type content="text/html; charset=gb2312" />
<style type="text/css">
body {
 font-size: 12px
}
a:visited {
 color: slategray; text-decoration: none
}
a:hover {
 color: slategray; text-decoration: underline
}
alink {
 color: slategray; text-decoration: none
}
</style>
<script type="text/javascript">
<!--
//可以打包为js文件;
var x0=0,y0=0,x1=0,y1=0;
var offx=6,offy=6;
var moveable=false;
var hover='orange',normal='#336699';//color;
var index=10000;//z-index;
//开始拖动;
function startDrag(obj)
{
 if(event.button==1)
 {
  //锁定标题栏;
  obj.setCapture();
  //定义对象;
  var win = obj.parentNode;
  var sha = win.nextSibling;
  //记录鼠标和层位置;
  x0 = event.clientX;
  y0 = event.clientY;
  x1 = parseInt(win.style.left);
  y1 = parseInt(win.style.top);
  //记录颜色;
  normal = obj.style.backgroundColor;
  //改变风格;
  obj.style.backgroundColor = hover;
  win.style.borderColor = hover;
  obj.nextSibling.style.color = hover;
  sha.style.left = x1 + offx;
  sha.style.top  = y1 + offy;
  moveable = true;
 }
}
//拖动;
function drag(obj)
{
 if(moveable)
 {
  var win = obj.parentNode;
  var sha = win.nextSibling;
  win.style.left = x1 + event.clientX - x0;
  win.style.top  = y1 + event.clientY - y0;
  sha.style.left = parseInt(win.style.left) + offx;
  sha.style.top  = parseInt(win.style.top) + offy;
 }
}
//停止拖动;
function stopDrag(obj)
{
 if(moveable)
 {
  var win = obj.parentNode;
  var sha = win.nextSibling;
  var msg = obj.nextSibling;
  win.style.borderColor     = normal;
  obj.style.backgroundColor = normal;
  msg.style.color           = normal;
  sha.style.left = obj.parentNode.style.left;
  sha.style.top  = obj.parentNode.style.top;
  obj.releaseCapture();
  moveable = false;
 }
}
//获得焦点;
function getFocus(obj)
{
 if(obj.style.zIndex!=index)
 {
  index = index + 2;
  var idx = index;
  obj.style.zIndex=idx;
  obj.nextSibling.style.zIndex=idx-1;
 }
}
//最小化;
function min(obj)
{
 var win = obj.parentNode.parentNode;
 var sha = win.nextSibling;
 var tit = obj.parentNode;
 var msg = tit.nextSibling;
 var *** = msg.style.display=="none";
 if(***)
 {
  win.style.height  = parseInt(msg.style.height) + parseInt(tit.style.height) + 2*2;
  sha.style.height  = win.style.height;
  msg.style.display = "block";
  obj.innerHTML = "0";
 }
 else
 {
  win.style.height  = parseInt(tit.style.height) + 2*2;
  sha.style.height  = win.style.height;
  obj.innerHTML = "2";
  msg.style.display = "none";
 }
}
//创建一个对象;
function xWin(id,w,h,l,t,tit,msg)
{
 index = index+2;
 this.id      = id;
 this.width   = w;
 this.height  = h;
 this.left    = l;
 this.top     = t;
 this.zIndex  = index;
 this.title   = tit;
 this.message = msg;
 this.obj     = null;
 this.bulid   = bulid;
 this.bulid();
}
//初始化;
function bulid()
{
 var str = ""
  + "<div id=xMsg" + this.id + " "
  + "style='"
  + "z-index:" + this.zIndex + ";"
  + "width:" + this.width + ";"
  + "height:" + this.height + ";"
  + "left:" + this.left + ";"
  + "top:" + this.top + ";"
  + "background-color:" + normal + ";"
  + "color:" + normal + ";"
  + "font-size:8pt;"
  + "font-family:Tahoma;"
  + "position:absolute;"
  + "cursor:default;"
  + "border:2px solid " + normal + ";"
  + "' "
  + "onmousedown='getFocus(this)'>"
   + "<div "
   + "style='"
   + "background-color:" + normal + ";"
   + "width:" + (this.width-2*2) + ";"
   + "height:20;"
   + "color:white;"
   + "' "
   + "onmousedown='startDrag(this)' "
   + "onmouseup='stopDrag(this)' "
   + "onmousemove='drag(this)' "
   + "ondblclick='min(this.childNodes[1])'"
   + ">"
    + "<span style='width:" + (this.width-2*12-4) + ";padding-left:3px;'>" + this.title + "</span>"
    + "<span style='width:12; border-width:0px;color:white;font-family:webdings; ' onclick='min(this)'>0</span>"
    + "<span style='width:12; border-width:0px; color:white;font-family:webdings; ' onclick='ShowHide(\""+this.id+"\",null)'>r</span>"
   + "</div>"
    + "<div style='"
    + "width:100%;"
    + "height:" + (this.height-20-4) + ";"
    + "background-color:white;"
    + "line-height:14px;"
    + "word-break:break-all;"
    + "padding:3px;"
    + "'>" + this.message + "</div>"
  + "</div>"
  + "<div id=xMsg" + this.id + "bg style='"
  + "width:" + this.width + ";"
  + "height:" + this.height + ";"
  + "top:" + this.top + ";"
  + "left:" + this.left + ";"
  + "z-index:" + (this.zIndex-1) + ";"
  + "position:absolute;"
  + "background-color:black;"
  + "filter:alpha(opacity=40);"
  + "'></div>";
 document.body.insertAdjacentHTML("beforeEnd",str);
}
//显示隐藏窗口
function ShowHide(id,dis){
 var bdisplay = (dis==null)?((document.getElementById("xMsg"+id).style.display=="")?"none":""):dis
 document.getElementById("xMsg"+id).style.display = bdisplay;
 document.getElementById("xMsg"+id+"bg").style.display = bdisplay;
}
//modify by haiwa @ 2005-7-14
//
//-->
</script>

<script  type="text/javascript">
<!--
function initialize()
{
 var a = new xWin("1",160,200,200,200,"窗口1","这效果是不是很酷呢?");
 var b = new xWin("2",240,200,100,100,"窗口2","呵呵,鼠标上来点一下看看啊");
 var c = new xWin("3",200,160,250,50,"窗口3","每一个都可以随意拖动哦~");
 ShowHide("1","none");//隐藏窗口1
}
window.onload = initialize;
//-->
</script>
</head>
<body oncontextmenu="return false" onselectstart="return false">
<a onclick="ShowHide('1',null);return false;" href="#">窗口1</a>
<a onclick="ShowHide('2',null);return false;" href="#">窗口2</a>
<a onclick="ShowHide('3',null);return false;" href="#/">窗口3</a>
</body>
</html>

预览效果

2006-09-12

前些日子整理伪对象伪元素,发现个好东西,总结一下,拿出来帖在这里:

<?xml version="1.0" encoding="gb2312"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>更加易用且人性化的表单样式</title>
<style type="text/css">
<!--
body {
  font-family: "宋体";
  font-size: 12px;
}
#logonForm {
  background: #333;
  padding: 3px;
  text-align: center;
  width: 350px;
  color: #FFF;
}
input {
  font-size: 12px;
  background: #FFF;
  border: 2px solid #000;
  padding: 1px;
}
input:hover,input:focus:hover {
  font-size: 12px;
  border: 2px solid #F60;
}
input:focus {
  font-size: 12px;
  border: 2px solid #F90;
}
-->
</style>
</head>

<body>
<form id="logonForm" name="logonForm" method="post" action="">
 用户名:
 <input name="id" type="text" size="12" />
 密码:
 <input name="password" type="text" size="12" />
 <label>
 <input name="Submit" type="submit"  value="登录" />
 </label>
</form>
</body>
</html>

只是给input加了个:focus属性,它就能在用户输入资料时感受到奇特的交互效果。非常有用不是么?

共1页 1