javascript - 在 jquery 模态对话框中获取文本框的值

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

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

$("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();
}

最佳答案

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

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

关于javascript - 在 jquery 模态对话框中获取文本框的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26283960/

相关文章:

javascript - 从模型上的数据库更改(after_commit 回调)使用 Faye 更新 Rails View

javascript - react : Bubbling up click events on nested components

asp.net-mvc - Jquery Ajax后有时会转向获取MVC

javascript - 如何使用 mdb.min.js 将选择框动态更改为 <ul><li>

c# - 静态存储库 - 解决方法

javascript - 使用 CSRF 保护同时发出多个 AJAX 请求

javascript - 我如何知道哪个 javascript 脚本将特定类添加到我的源代码中

javascript - 无法激活基于 JavaScript IE 识别的事件

asp.net-mvc-3 - 在 ASP.NET MVC 3 中跨区域共享 View 的最佳方式

asp.net - 未为 ASP.Net MVC 3 DropDownListFor 设置所选值