2012-05-15 85 views
-1

我在我的網頁上使用了一個jQuery表格添加行插件,它在Chrome和IE9上的本地桌面上工作正常。但當我上傳項目到服務器,它仍然在Chrome上工作正常,但沒有發生在IE9上,(有一個addrow按鈕,當我點擊它,沒有行被添加)。jquery無法在IE9上工作

你知道爲什麼會發生這種情況嗎?

我使用最新的jQuery版本。

編輯:

<table id="tblotherlicence" style="width:800px" cellspacing="2" cellpadding="3">  
     <tr><td class="formtitle" colspan="5">OTHER PROFESSIONAL LICENSURE<a style="font-size:7pt">(e.g.,registered psychiatric nurse; registered massage therapist; registered social worker)</a></td></tr> 
     <tr><td class="formlabel">Profession</td> 
      <td class="formlabel">Licence Number</td> 
      <td class="formlabel">Jurisdiction</td> 
      <td class="formlabel">Date of Expiry</td> 
      <td class="formlabel"><input class="addrow" type="button" value="Add Row" /></td></tr> 
     <tr> 
      <td><asp:TextBox ID="Licence1" runat="server"></asp:TextBox> 
      </td> 
      <td><asp:TextBox ID="LicenceNumber1" runat="server"></asp:TextBox> 
      </td> 
      <td><asp:TextBox ID="Jurisdiction1" runat="server"></asp:TextBox> 
      </td> 
      <td><asp:TextBox ID="ExpiryDate1" runat="server"></asp:TextBox></td> 
      <td><input class="delrow" type="button" value="Delete Row" /></td> 
     </tr> 
    </table> 

<script type="text/javascript"> 
      $(document).ready(function() { 
       $("#<%=ExpiryDate1.ClientID%>").datepicker({ 
         yearRange: '1950:2015', 
         changeYear: true, 
         changeMonth: true, 
     257  }); 
       $(".addrow").btnAddRow(function() { 
        var i; 
        var rowCount = $("#tblotherlicence tr").length; 
        for (i = 3; i <= rowCount; i++) { 
         $("#tblotherlicence tr:nth-child(" + i + ") td:nth-child(4) input[type='text']").attr("id", "MainPlaceHolder_RecordofNursing1_ExpiryDate" + (i - 2));    
         $("#tblotherlicence tr:nth-child(" + i + ") td:nth-child(4) input[type='text']").removeAttr("class"); 
         $("#tblotherlicence tr:nth-child(" + i + ") td:nth-child(4) input[type='text']").datepicker({ 
           yearRange: '1950:2015', 
           changeYear: true, 
           changeMonth: true, 
         }); 
        } 
       }); 
       $(".delrow").btnDelRow(); 
      }); 
    </script> 

錯誤是 「SCRIPT1028:預期標識符,字符串或數字xxxxx.aspx,257行字符21」,我已標記線257這僅僅是一個閉括號

+9

嗨,皮塔。提問時始終顯示代碼。 –

+1

發表您的代碼或一些代碼示例jsFiddle。也許一個網頁的URL在哪裏發生? –

+0

什麼樣的服務器?檢查瀏覽器是否存在js錯誤消息。此外,請確保ie9 –

回答

0

後取出後逗號changeMonth

$("#<%=ExpiryDate1.ClientID%>").datepicker({ 
    yearRange: '1950:2015', 
    changeYear: true, 
    changeMonth: true // Right here 
}); 

「預期標識符,字符串或數字的」是指它接收不同的東西,它是應該。在這種情況下,因爲您有逗號,所以在changeMonth之後會有更多內容出現,但您可以關閉它。

有些瀏覽器對錯別字和這樣的小錯誤往往非常寬大,但IE更嚴格。這可能是一件好事(強制執行正確的代碼),但這也意味着您會遇到更多錯誤。

+0

這就是問題所在!非常感謝!!! – pita

0

這個「問題」並不特定於jQuery。 IE不喜歡在對象聲明中使用尾隨逗號,而其他瀏覽器會忽略它。

我建議通過JSLint運行您的代碼來捕獲這樣的錯誤。您可能會得到比您在IE9中獲得的更好的錯誤消息。你會有更清潔的代碼!