用css来实现Focus效果的提交信息表单

Feb 8, 2007 by 大龙

蛮酷的效果,为了兼容ie6使用了一些简单的javascript代码,效果如下:

form.htm

xhtml代码:

<form action="#" method="post" name="myform" id="myform">
<div class="bo"><label for="name">姓名:</label>
<input type="text"size="20" name="name" id="name" maxlength="10" /></div>
<div class="bo"><label for="tel">电话:</label>
<input type="text" size="20" name="tel" id="tel" maxlength="16" /></div>
<div class="bo"><label for="mo">主题:</label>
<input type="text" size="30" name="mo" id="mo" maxlength="20" /></div>
<div class="bo"><label for="con">内容:</label>
<textarea cols="40" rows="8" name="con" id="con"></textarea></div>
<div class="btcenter"><input type="submit" class="bt" value="Send" />
<input type="reset" class="bt" value="Reset" /></div></form>

css代码:

form{
 
margin: 0px auto;
 
width: 450px;
 
border: solid 1px #CCCCCC;
}
 
.bo{
 
border-bottom: solid 1px #CCCCCC;
}
 
label{
 
float: left;
 
padding: 10px 0px 4px 30px;
}
 
input{
 
padding: 1px;
}
 
input,textarea{
 
border: 1px solid #CCCCCC;
 
margin: 5px 0px;
}
 
textarea{
 
padding: 2px;
}
 
.bt{
 
width: 38px;
 
height: 20px;
 
font-size: 11px;
 
border: solid 1px #CCCCCC;
 
background: #FBFBFB;
 
text-align: center;
}
 
.btcenter{
 
text-align: center;
 
clear: left;
 
padding: 4px 0px 0px;
}
 
/
*----下面是选中表单时的变化效果,大家可以自由发挥的---*/
.sffocus {
 
background: #F0F9FB; /*----for IE----*/
 
border: 1px solid #1D95C7;
}
 
textarea:focus, input:focus {
 
background: #F0F9FB; /*----for firefox......----*/
 
border: 1px solid #1D95C7;
}
 
body {
 
font-family: Arial, Helvetica, sans-serif;
 
font-size: 12px;
 
color: #666666;
 
margin-top: 20px;
}

js代码(注:js代码主要针对IE6的,IE7已经支持focus了,FIREFOX、NS…..不需要。):

function suckerfish(type, tag, parentId) {
if (window.attachEvent) {
window.attachEvent("onload", function() {
var sfEls = (parentId==null)?document.getElementsByTagName(tag):document.getElementById(parentId).getElementsByTagName(tag);
type(sfEls);
});
}
}
sfFocus = function(sfEls) {
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onfocus=function() {
this.className+=" sffocus";
}
sfEls[i].onblur=function() {
this.className=this.className.replace(new RegExp(" sffocusb"), "");
}
}
}
suckerfish(sfFocus, "INPUT");
suckerfish(sfFocus, "TEXTAREA");

Tags: , ,

Google AD

« MYSQL出错代码列表及使用方法举例  | 不用表格实现新闻列表–简洁,清晰 »

评论(Leave a Reply)

  • :em27:
  • :em46:
  • :em50:
  • :em62:
  • :em52:
  • :em30:
  • :em61:
  • :em56:
  • :em48:
  • :em49:
  • :em25:
  • :em43:
  • :em36:
  • :em72:
  • :em31:
  • :em45:
  • :em39:
  • :em21:
  • :em41:
  • :em40:
  • :em35:
  • :em54:
  • :em20:
  • :em32:
  • :em37:
  • :em67:
  • :em38:
  • :em42:
  • :em28:
  • :em34:
  • :em57:
  • :em63:
  • :em59:
  • :em23:
  • :em26:
  • :em70:
  • :em44:
  • :em64:
  • :em51:
  • :em71:
  • :em55:
  • :em58:
  • :em33:
  • :em69:
  • :em29:
  • :em60:
  • :em19:
  • :em65:
  • :em68:
  • :em53:
  • :em22:
  • :em24:
  • :em47:
  • :em66: