【问题标题】:Get values of Textbox in jquery Modal dialog在 jquery 模态对话框中获取文本框的值
【发布时间】:2014-10-10 01:38:37
【问题描述】:

我正在像这样在 jquery 模态对话框中打开一个视图

$("a.OpenView").on('click', function () {
       ></div>")
            .addClass("dialog closePopup")
            .attr("id", "popup1")
            .appendTo("body")
            .load("../../ControllerName/_partialView")
            .dialog({
                title: "LogIn",
                modal: true,
                height: "auto",
                minHeight: 260,
                maxHeight: 260,
                width: 450,
                left: 0,
                zIndex: 1001
            });

    });

HTML

<table cellpadding="0" cellspacing="0">
        <tr>
          <td align="center"><input name="" type="text" value="" title="User Name" class="width190" id="txtUserName" onfocus="txtFocus(this)" onblur="txtFBlur(this,'0')"/></td>
          <td align="center"><input name="" type="password" value=""  title="Password" class="width190" id="txtPassword" onfocus="txtFocus(this)" onblur="txtFBlur(this,'1')"/></td>
        </tr>
        <tr>
          <td colspan="2" align="center"><input name="" type="submit" class="blue_btn" value="Sign In"  id="btnLogIn" onclick="javascript:return LogIn()"/></td>
        </tr>

      </table>

现在,一旦我关闭对话框,然后我再次重新打开它并输入用户名和密码...我得到 "" 作为两个文本框的值...

这可能是什么原因,我做错了什么?

登录功能在这里

function LogIn() {
    var username = $('#txtUserName').val();
    var password = $('#txtPassword').val();
}

【问题讨论】:

    标签: javascript jquery asp.net-mvc-3 jquery-dialog


    【解决方案1】:

    我认为您在 DOM 中有 2 个具有相同 ID 的元素。 尝试销毁对话框而不是关闭它。

    $("#popup1").dialog('destroy').remove()
    

    【讨论】:

    • 有什么办法销毁它吗?
    • $("#popup1").dialog('destroy').remove()
    【解决方案2】:

    嘿在父页面中创建closeframe函数

    function closeIframe() {
        $('#divClose').dialog('destroy');
    }
    

    并从子页面调用该函数,您可以说model popup

    window.parent.closeIframe();
    

    参考可以访问我的Link

    【讨论】:

      【解决方案3】:

      尝试使用 Jquery 对话框的“beforeClose”事件

      查看更多Documentation here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-18
        • 2011-01-22
        相关资源
        最近更新 更多