javascript
  • asp.net
  • 2011-07-11 77 views 1 likes 
    1

    我在我的代碼中有以下內容,它在IE 7和8中工作正常,但它不再適用於IE 9(除非用戶以兼容模式運行...)IE9 Javascript未定義變量

    <asp:Label ID="invNumLink" runat="server" Font-Underline="true" ForeColor="Blue" Text='<%# Eval("Order_No") %>' createDate='<%# string.Format(Eval("create_date").ToString(),"MM/dd/yyyy") %>' 
               operatorNo='<%# Eval("operator_no") %>' orderNo='<%# Eval("Order_No") %>' loc='<%# Eval("Location") %>' table='<%# Eval("table_no") %>' recall='<%# Eval("recall_code") %>' 
               orderID='<%# Eval("ID") %>' acrID='<%# Eval("ACR_ID") %>' 
               onclick="goToDetail(this.orderNo,this.createDate, this.operatorNo, this.loc, this.table, this.recall, this.orderID, this.acrID);" style="cursor:pointer" ></asp:Label> 
    
    <script type="text/javascript"> 
        function goToDetail(orderNo, createDate, operatorNo, loc, table, recall, orderID, acrID) { 
         var URL = 'OrderDetailView.aspx?orderNo=' + orderNo + '&' + 'createDate=' + createDate + '&' + 'operatorNo=' + operatorNo + '&' + 'loc=' + loc + '&' + 'table=' + 
                 table + '&' + 'recall=' + recall + '&' + 'id=' + orderID + '&' + 'acrID=' + acrID; 
         day = new Date(); 
         id = day.getTime(); 
         window.open(URL, id, 'toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=1100,height=700,left = 62,top = 15') 
        } 
    </script> 
    

    在IE9中,所有發送到「goToDetail」函數的值都是未定義的。有想法該怎麼解決這個嗎?

    編輯

    我解決了這個由後面的代碼將調用的javascript:

    invNumLink.Attributes.Add("onclick", string.Format("goToDetail('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}'); return false;", item.GetDataKeyValue("Order_No").ToString(), 
           string.Format(item.GetDataKeyValue("Create_Date").ToString(), "MM/dd/yyyy"),item.GetDataKeyValue("Operator_No").ToString(), item.GetDataKeyValue("Location").ToString(), 
           item.GetDataKeyValue("table_no").ToString(), item.GetDataKeyValue("recall_code").ToString(), item.GetDataKeyValue("ID").ToString(),item.GetDataKeyValue("ACR_ID").ToStrin 
    

    感謝,

    亞倫

    +0

    您是否嘗試過在您的標記之前移動javascript塊? –

    +0

    這不會幫助 - 問題是IE9不會像舊版瀏覽器那樣將非標準屬性的屬性值移交給用戶。 – Pointy

    +0

    @ Pointy - 這完全不是很酷.... :( – Aaron

    回答

    3

    你可以使用數據的屬性,它的工作是這樣的:

    相反的:

    <span operatorNo="value"> 
    

    您使用

    <span data-operatorNo="value"> 
    

    而且隨着

    this.getAttribute("data-operatorNo") 
    
    訪問它

    這適用於IE6並記錄爲在IE7 +中工作。 Do HTML5 custom data attributes 「work」 in IE 6?

    1

    我知道這是醜陋的.. 。但也許直接傳遞值會解決你的問題。

    <asp:Label ID="invNumLink" runat="server" Font-Underline="true" ForeColor="Blue" Text='<%# Eval("Order_No") %>' createDate='<%# string.Format(Eval("create_date").ToString(),"MM/dd/yyyy") %>' 
               operatorNo='<%# Eval("operator_no") %>' orderNo='<%# Eval("Order_No") %>' loc='<%# Eval("Location") %>' table='<%# Eval("table_no") %>' recall='<%# Eval("recall_code") %>' 
               orderID='<%# Eval("ID") %>' acrID='<%# Eval("ACR_ID") %>' 
               onclick="goToDetail('<%# Eval("Order_No") %>','<%# string.Format(Eval("create_date").ToString(),"MM/dd/yyyy") %>', '<%# Eval("operator_no") %>', '<%# Eval("Location") %>', '<%# Eval("table_no") %>','<%# Eval("recall_code") %>', '<%# Eval("ID") %>', '<%# Eval("ACR_ID") %>');" style="cursor:pointer" ></asp:Label> 
    
    +0

    它是醜陋的,但我給它一個鏡頭... – Aaron

    +0

    不會用在Eval語句裏面的雙引號,我現在記得它是爲什麼我做了這是我之前的做法,我想我必須在代碼後面添加一個樣式...... – Aaron

    1

    對於HTML標籤不規範的屬性,我相信你需要使用element.getAttribute("attName")獲取的HTML,而不是直接與element.attName訪問這些定義非標準屬性。要保持標準,您還應該將自定義數據屬性添加爲「數據 - 」。

    相關問題