【问题标题】:how to pass a javascript variable to onMouseOver event如何将 javascript 变量传递给 onMouseOver 事件
【发布时间】:2011-09-12 11:26:58
【问题描述】:

如何在 mouseOver 事件中使用 js 变量?

这是我的代码:

   <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>

它看起来不像这样工作:)。

谢谢。 !

【问题讨论】:

    标签: javascript asp.net vb.net


    【解决方案1】:

    试试这个:

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

    【讨论】:

      【解决方案2】:

      我发现我需要 qoutes:

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

      必须是

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

      您的解决方案不起作用。如果标签包含 runat="server" 属性,则不允许使用“”标签。这就是为什么我一开始没有使用它,但我忘了提及它。很抱歉。

      感谢您的回答!

      【讨论】:

        【解决方案3】:

        试试这个:

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

        【讨论】:

        • 这行不通。你测试了吗?引号正在转义字符串。
        猜你喜欢
        • 2015-01-03
        • 2018-08-03
        • 1970-01-01
        • 2014-01-28
        • 2019-07-07
        • 1970-01-01
        • 1970-01-01
        • 2014-09-30
        • 2020-01-11
        相关资源
        最近更新 更多