2010年10月15日 星期五

prototype

$('xxx').readAttribute('xxx')
$('xxx').writeAttribute('xxx')

$(element).show();
$(element).hide();

$(element).up('div')
$(element).down('div')

$(element).select('div') //指定選tag
$(element).getElementsBySelector('div#xxx') //可以指定id, 或 input[]

$(element).getElementsBySelector('xxx').first() //若回傳是list, 可用 [0], 或 .first() 取element

$(element).each(function (el, index) {
    //
});


$(element).childElements()[0].addClassName('current');
$(element).childElements()[0].removeClassName('current');
   
           
$(element).setStyle({'display':'block'});           

document.observe("dom:loaded", function() {
    $$("xxx").each( function(element, index){
        element.observe("click",function(pEvent){
            //           
        } );
    } );
});

2010年10月1日 星期五

regex 檢查 example

來源: http://tw.myblog.yahoo.com/davidbulll/article?mid=79&prev=277&next=76




<form onsubmit="return check();">
<input type="text" name="t1">
<input type="submit">
</form>
<script language="javascript">
--------------------------------檢查數字(整數)

function check() {
 re = /^\d+$/;
 if (!re.test(document.forms[0].t1.value)) {
    alert("欄位不能空白且只允許輸入數字");
    document.forms[0].t1.focus();
    return false;
 }
 return true;
}

--------------------------------檢查數字可有小數

function check(thisname) {

 if (isNaN(document.getElementById(thisname).value)) {
    alert("欄位不能空白且只允許輸入數字");
    document.getElementById(thisname).focus();
    return false;
 }
 }

--------------------------------檢查是否有填資料
function gbchk(theForm)               
{            
  if (theForm.name.value == "")               
  {               
    alert("請輸入姓名!!");               
    theForm.name.focus();               
    return (false);               
  }   
  if (theForm.content.value == "")               
  {               
    alert("請輸入留言內容!!");               
    theForm.content.focus();               
    return (false);               
  }    
  return (true);               
}               
//-->
----------------------------------檢查是否為MAIL格式
    re1 = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
 if (re1.exec(theForm.email.value) == null)
 {
 alert("你的電子郵件格式不合!");
    theForm.email.focus();               
    return (false);               
 }
</script>
----------------------------------檢查日期格式

--------------------------------------------------------
 <input name="Submit2" type="submit"  value="送出"  onclick="return check()">