我正在像这样在 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/