數字驗證和table格式(KAYAK)

添加table footer:

<table border="1">

   <thead>
      <tr>
         <th>表頭單元格一</th>
         <th>表頭單元格二</th>
      </tr>
   </thead>

   <tbody>
      <tr>
         <td>標準單元格一</td>
         <td>標準單元格二</td>
      </tr>
      <tr>
         <td>標準單元格一</td>
         <td>標準單元格二</td>
      </tr>
   </tbody>

   <tfoot>
      <tr>
         <td>標準單元格一</td>
         <td>標準單元格二</td>
      </tr>
   </tfoot>
</table>


設置table的列不會隨着內容的增加而變寬: this

table-layout:fixed;word-break:break-all;

驗證文本框內只有小數點和數字: spa

$('.numberValue').bind('blur', function(event){
         var re = /^\d+(?=\.{0,1}\d+$|$)/;
          if(this.value != '' && !re.test(this.value))
          {
               alert('Please enter a valid number.');
               this.value = '';
               $(this).focus();
          }
});

也能夠這樣寫:

function checkNumber(currentNum)
{
     var re = /^\d+(?=\.{0,1}\d+$|$)/;
     if(currentNum.value != '' && !re.test(currentNum.value))
     {
          alert('Please enter a valid number.');
          currentNum.value = '';
          currentNum.focus();
      }

}

只容許輸入數字和一個小數點: code

$('.numberValue').bind('keypress', function(event){

     var getValue = $(this).val();
     if(getValue.length == 0 && event.which == 46)//the first char is '.'
      {
           event.preventDefault();
           return;
       }
       if(getValue.indexOf('.') != -1 && event.which == 46)
       {
           event.preventDefault();
           return;
        }
        if(event.which && (event.which < 48 || event.which > 57) && event.which != 8 && event.which != 46)
         {
             event.preventDefault();
              return;
         }
 });
相關文章
相關標籤/搜索