我遇到了一个可能就在我面前的 jQuery 对话框的问题,但我无法弄清楚......
对话框工作正常。它显示字段并发送信息,如果是,则返回验证消息。我的问题是,当我初始化它时,我告诉它在 if 中隐藏一个 div,它确实如此。打开时 div 不存在,但如果我尝试发送信息并返回验证消息,它会显示 div。
这是调用对话框的js:
$(function () {
$('.openDialog').click(function () {
$.ajax({
url: this.href,
type: 'GET',
cache: false,
data: { idUsuario: $('#idUsuario').val() },
success: function (result) {
$('#result').html(result).dialog('open');
$('#formButtom').hide();
}
});
return false;
});
$('#result').dialog({
autoOpen: false,
modal: true,
show: { effect: "drop", direction: "up" },
dialogClass: "dialog",
width: 400,
resizable: false,
position: "center",
buttons: {
"Confirmar": function () {
$("form").submit();
},
"Cancelar":function () { $('#result').dialog('close'); }
}
});
});
function dialogSucces(result) {
if (result.cadastro) {
$('#result').dialog('close');
window.location.href = '/usuario/index';
} else {
$('#result').html(result);
}
}
这是html:
<form id="createUsuarioForm">
Nome
<div class="editor-field">
@Html.EditorFor(model => model.Nome)<br />
@Html.ValidationMessageFor(model => model.Nome, String.Empty, new { @class = "text-error"})
</div>
<br />
E-mail / Login
<div class="editor-field">
@Html.EditorFor(model => model.Login)<br />
@Html.ValidationMessageFor(model => model.Login, String.Empty, new { @class = "text-error"})
</div>
<br />
<div id="formButtom" class="row demo-row">
<div class="span2">
<input type="submit" value="Confirmar" class="btn btn-primary" />
</div>
<div class="span2">
@Html.ActionLink("Cancelar", "Index", "Usuario", new { @class = "btn btn-primary" })
</div>
</div>
</form>
我看过这篇文章:jQuery Show/Hide not working after postback并尝试在函数中执行此操作,但没有成功:
$(function () {
$('.openDialog').click(function () {
$.ajax({
url: this.href,
type: 'GET',
cache: false,
data: { idUsuario: $('#idUsuario').val() },
success: function (result) {
$('#result').html(result).dialog('open');
$('#formButtom').hide();
}
});
return false;
if (this.isPostback) { $('#formButtom').hide(); };
});
有谁知道我做错了什么?