2011-09-12 57 views
0

如何在mouseOver事件中使用js變量?如何將JavaScript變量傳遞給onMouseOver事件

這裏是我的代碼:

<script type="text/javascript"> 
       window.String1 = <%=GetLocalResourceStringEscaped("String1")%>; 
       window.String2 = <%=GetLocalResourceStringEscaped("String2")%>; 
       </script> 
       <label runat="server" id="labelWeight" onmouseout="HelpOut(this);" onmouseover="Help(this,window.String1,window.String2);"> 
        <asp:Localize ID="LocPWeight" runat="server" meta:Resourcekey="ProductWeightInGrams" 
          Text="Product Weight in Grams"></asp:Localize> 
       </label> 

,它看起來像它不以這種方式工作:)。

謝謝。 !

回答

0

我搞清楚我需要qoutes:

 window.String1 = <%=GetLocalResourceStringEscaped("String1")%>; 

必須

 window.String1 = '<%=GetLocalResourceStringEscaped("String1")%>'; 

你的營養不起作用。如果標籤包含runat =「server」屬性「<%=%>」,則不允許使用標籤。這就是爲什麼我第一次沒有使用它,但我忘了提及它。對不起。

謝謝你的回答!

0

試試這個:

onmouseover='function(){Help(this,<%= GetLocalResourceStringEscaped("String1") %>,<%= GetLocalResourceStringEscaped("String2") %>);}' 
+0

這是行不通的。你測試過了嗎?引號正在轉義字符串。 –

0

試試這個:

onmouseover = 'Help(this,<%=GetLocalResourceStringEscaped("String1")%>, <%=GetLocalResourceStringEscaped("String2")%>);'; 
相關問題