代码之家  ›  专栏  ›  技术社区  ›  stoic Kobus Kleynhans

回发时丢失文本框值

  •  9
  • stoic Kobus Kleynhans  · 技术社区  · 16 年前

    在一个页面中我有一个链接;单击它会打开一个对话框,并为该对话框设置一个文本框值。

    <a href="#" onclick="javascript:expand('https://me.yahoo.com');
    jQuery('#openiddialog').dialog('open'); return false;">
    <img id="yahoo" class="spacehw" src="/Content/Images/spacer.gif" /></a>
    

    脚本:

    <script type="text/javascript">
      jQuery(document).ready(function () {
        jQuery("#openiddialog").dialog({
            autoOpen: false,
            width: 600,
            modal: true,
            buttons: {
               "Cancel": function () {
                  $(this).dialog("close");
               }
            }
        });
    });
    function expand(obj) {
        $("#<%=openIdBox.ClientID %>").val(obj);
    }
    

    对话框:

    <div id="openiddialog" title="Log in using OpenID">
    <p>
        <asp:Label ID="Label1" runat="server" Text="OpenID Login" />
        <asp:TextBox ID="openIdBox" EnableViewState="true" runat="server" />
        <asp:JButton Icon="ui-icon-key" ID="loginButton" runat="server" Text="Authenticate" OnClick="loginButton_Click" />
        <asp:CustomValidator runat="server" ID="openidValidator" ErrorMessage="Invalid OpenID Identifier" ControlToValidate="openIdBox" EnableViewState="false" OnServerValidate="openidValidator_ServerValidate" />
        <br />
        <asp:Label ID="loginFailedLabel" runat="server" EnableViewState="False" Text="Login failed" Visible="False" />
        <asp:Label ID="loginCanceledLabel" runat="server" EnableViewState="False" Text="Login canceled" Visible="False" />
    </p>
    </div>
    
    2 回复  |  直到 16 年前
        1
  •  7
  •   stoic Kobus Kleynhans    16 年前

    我想:

    $("#openiddialog").parent().appendTo(jQuery("form:first"));
    

    整个脚本现在应该如下所示:

    <script type="text/javascript">
    jQuery(document).ready(function () {
        jQuery("#openiddialog").dialog({
            autoOpen: false,
            width: 600,
            modal: true,
            buttons: { "Cancel": function () {
                $(this).dialog("close");
            }
            }
    });
    $("#openiddialog").parent().appendTo(jQuery("form:first"));
    });
    function expand(obj) {
        $("#<%=openIdBox.ClientID %>").val(obj);
    }
    

        2
  •  1
  •   Kate    16 年前

    为什么在文本框ID之前添加#?我认为你应该使用:

    function expand(obj) {
        $("<%=openIdBox.ClientID %>").val(obj);
    }
    
    推荐文章