JavaScript經典代碼【一】【javascript HTML控件獲取值】


javascript HTML控件獲取值
 

1.下拉列表框選定值
ddlPageSize.options[ddlPageSize.selectedIndex].value
ddlPageSize.options[ddlPageSize.selectedIndex].text

復選框
$get('chkGoogle').checked

控件隱藏與顯示:
   document.getElementById("控件名").style.display='' //顯示
        document.getElementById("控件名").style.display='none'

textBox:
   document.getElementById("控件名").value        //獲取或設值文本框值
checkbox:
   document.getElementById('chkComJoin').checked //判斷是否已選擇
  
   example:
    if(document.getElementById('chkComJoin').checked)
            document.getElementById('trcomjoin').style.display=''
        
label:
   document.getElementById("控件名").innerHTML   //獲取或設值標簽值


網址驗證:
   var urlreg1=/^[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/
                if (!urlreg1.test(a.value))//驗證網址
                {
                                  
                    document.getElementById("lblCheckWebFormat2").innerHTML="請正確錄入企業網址!";
                                   
                }
                 else
                {
                     document.getElementById("lblCheckWebFormat2").innerHTML="";
                }

防止返回字
符為類型 :
   if(typeof(返回值變量)!="undefined")



table添加行:   insertRow()
        insertCell()
        表ID.rows(0).cells(0).innerText   或   innerHTML //獲取或設值某單元格

   var   curRow=document.getElementById(表ID).rows.count;//得到表的最大行數,作為插入位置(第幾行)
    var x=document.getElementById(name).insertRow(curRow); //插入一行在curRow位置,並定義x行對象
       var C1=x.insertCell(0);//插入一個單元格(列)在0位置,並定義C1列對象
       var C2=x.insertCell(1);
       var C3=x.insertCell(2);
       var C4=x.insertCell(3);
       var C5=x.insertCell(4);
       C1.innerHTML=ary[0];//為單元格賦值,
       C1.style.display='none';
       C2.innerHTML=ary[1];
       C2.style.display='none';
       C3.innerHTML='<a href=\"'+ary[0]+'\" target=\"_blank\">'+ary[2]+'</a>';
       C4.innerHTML=ary[3];
       C4.style.display='none';
        C5.innerHTML="<input type=\"button\" value=\"刪除\" 
     onclick=\"if(confirm('確實要刪除當前項嗎?')){DelteFile     ('"+ary[0]+';'+aryof1+"');this.parentNode.parentNode.removeNode(true)}\">";
       


日期控件使用:
    
   將日期控件放入彈出的新頁面中,"<base target="_self"></base>"加入<HEAD></HEAD>之間 
    <script>
    //返回值
    function getValue(Value)
    {
           window.returnValue=Value;
            window.close();
       }
    </script>

模式對話框:
   var str = window.showModalDialog("ShowCom.aspx","compar","dialogWidth=750px;dialogHeight=600px;status=no;scrollbars=no");//str接受返回值
 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM