方式一:<input type="submit" class="u-btnblue" value="保存" />
好处:验证直接用实体就可以
缺点:验证不能多样化,不是很灵活哦。
方式二: <input type="button" class="u-btnblue" value="添加关键词" id="AddKeyWords" />
$("#AddoldNode").click(function () {
if ("0" == $("#hfTextBookID").val()) {
top.art.dialog({
title: '消息',
content: '请先选择书本!',
icon: 'warning',
ok: function () {
}
});
return false;
}
var location = encodeURI("/Admin/Catalog/GetKnoledgeSecond?strBookID=" + $("#hfTextBookID").val();
$.getJSON(location,
function (data) {
if (data != null || data != "") {
zNodes = data;
}
}
);
});
好处:可以自己写验证
缺点:只能一次提交
方式三:利用AjaxSUbmit
步骤一:<script language="JavaScript" src="@Web.APP_Configs.ProgramConfig.JScriptAddress/Admin/jquery.form.js" type="text/javascript"></script>
步骤二:@using (Html.BeginForm("Add", "Book", FormMethod.Post, new { id = "textBook",enctype = "multipart/form-data" })){}
步骤三: <input type="button" class="u-btnblue" value="保存" id="save"/>
$("#save").click(function () {
if ($("#nSDescribe").val().replace(/\s+/g, "") == "") {
$("#testnSDescribe").html("*此项不可为空!");
return false;
} else {
if ($("#nSDescribe").val().replace(/\s+/g, "").length > 2000) {
$("#testnSDescribe").html("*此项不可大于2000!");
return false;
} else {
$("#testnSDescribe").html("");
}
}
$("#textBook").ajaxSubmit({
url: "/Admin/Book/Add",
type: "post",
success: function (msg) {
if (msg == "1") {
top.art.dialog({
title: '消息',
content: '添加成功!',
icon: 'succeed',
ok: function () {
window.location.href = "/Admin/Book/Index"
},
close: function () {
window.location.href = "/Admin/Book/Index"
}
})
}
else {
top.art.dialog({
title: '消息',
content: '添加失败!',
icon: 'error',
ok: function () {
}
})
}
}
});
});
});
好处:验证灵活,想什么时候提交就什么时候提交