C#技术百科
问问你的心你有没有信心 做事情要专一坚定,执着

<script type="text/javascript">
function $(id)
{
 return document.getElementById(id);
}
function cdiv(e,regs,messucc,mesfail){
///无值的话
var reg = new RegExp(regs, "igm");
var messucc="<a href='#'>"+messucc+"</a>";// 正确的提示
var mesfail = "<a href='#'>"+mesfail+"</a>";//错误的提示
  var t=e.offsetTop;
  var l=e.offsetLeft;
  var ee=e;
  while(ee=ee.offsetParent)
  {
   t+=ee.offsetTop;
   l+=ee.offsetLeft;
  }
       if(!reg.test(e.value))
    {
  
     if($('div1'+e.id)==undefined)
   {
    var createDiv = document.createElement("div");
    createDiv.style.border = "1px solid #ccc";
    createDiv.setAttribute("id",'div1'+e.id);
    createDiv.style.background = "#f60";
    createDiv.setAttribute("position","absolute");
    createDiv.style.height = 10;
    createDiv.style.width = 100;
    createDiv.style.top =t;
    ///获取文本框后面的坐标
    createDiv.style.left =l+e.offsetWidth+3;
    createDiv.style.position ="absolute";
    
    createDiv.innerHTML=mesfail;//"<a href='#'>faile</a>"
    
    
    var tlink = document.getElementById("tlink");
    var parent = tlink.parentNode;
    if(parent.lastChild == tlink) {
    parent.appendChild(createDiv);
    } else {
    parent.insertBefore(createDiv, tlink.nextSibling);
    }
   
   }
   else
   {
    $('div1'+e.id).innerHTML=mesfail;
   }
    }
    ///通过的的话
    else
    {
      if($('div1'+e.id)==undefined)
   {
    var createDiv = document.createElement("div");
    createDiv.style.border = "1px solid #ccc";
    createDiv.setAttribute("id",'div1'+e.id);
    createDiv.style.background = "#f60";
    createDiv.setAttribute("position","absolute");
    createDiv.style.height = 10;
    createDiv.style.width = 100;
    createDiv.style.top =t;
    ///获取文本框后面的坐标
    createDiv.style.left =l+e.offsetWidth+3;
    createDiv.style.position ="absolute";
    
    createDiv.innerHTML=messucc;
    
    
    var tlink = document.getElementById("tlink");
    var parent = tlink.parentNode;
    if(parent.lastChild == tlink) {
    parent.appendChild(createDiv);
    } else {
    parent.insertBefore(createDiv, tlink.nextSibling);
    }
   
   }
   else
   {
    $('div1'+e.id).innerHTML=messucc;
   }
    }
 
}

 


</script>
<table width="525" height="138" >
<tr><td height="106">&nbsp;</td>
<td></td></tr><tr><td><input name="text" type="text" id="tlink" onblur="cdiv(this,'^\\d+$','success','fail')" width="60px" /></td><td></td></tr></table>

posted on 2008-06-10 14:06  王德田  阅读(194)  评论(0编辑  收藏  举报