11-Add页面

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Add</title>
<script src="~/Script/jquery-1.10.2.min.js"></script>
<script src="~/Content/utf8-asp/ueditor.config.js"></script>
<script src="~/Content/utf8-asp/ueditor.all.min.js"></script>
<script src="~/Content/utf8-asp/lang/zh-cn/zh-cn.js"></script>
</head>
<body>
<form id="f1">
<div>
<table>
<tr>
<td>信息标题</td>
<td><input id="Text1" type="text" name="Title" /><span id="s1" style="color:red">*</span></td>
</tr>
<tr>
<td>发布人</td>
<td><input id="Text1" type="text" name="Name" /><span id="s2" style="color:red">*</span></td>
</tr>
<tr>
<td>类别</td>
<td>
<input id="Radio1" type="radio" name="Type" value="1" />二手
<input id="Radio1" type="radio" name="Type" value="2" />采购
<input id="Radio1" type="radio" name="Type" value="3" />组队
<input id="Radio1" type="radio" name="Type" value="4" />兼职
</td>
</tr>
<tr>
<td>类别图片</td>
<td>
<input type="file" id="file1" name="file1" />
<input type="hidden" id="TypeImg" name="TypeImg" />
</td>
</tr>
<tr>
<td colspan="2">
<script id="editor" type="text/plain" style="1024px;height:500px; " name="Context">

</script>

</td>
</tr>
<tr>
<td colspan="2">
<input type="file" id="file" name="file" />
<input type="hidden" id="FileName" name="FileName" />
</td>
</tr>
<tr>
<td colspan="2">
<input type="button" id="btnAdd" value="发布" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
<script>
//实例化编辑器
//建议使用工厂方法getEditor创建和引用编辑器实例,如果在某个闭包下引用该编辑器,直接调用UE.getEditor('editor')就能拿到相关的实例
var ue = UE.getEditor('editor');
$(function () {
//文件上传
$("#file").change(function () {
$.ajax({
url: "/News/UpdateLoad",
data: new FormData($("#f1")[0]),
contentType: false,
processData: false,
cache: false,
type: 'POST',
success: function (data) {
alert(data);
$("[name=FileName]").val(data);

}

})
})

//类型图片上传
$("#file1").change(function () {
$.ajax({
url: "/News/UpdateLoad_One",
data: new FormData($("#f1")[0]),
contentType: false,
processData: false,
cache: false,
type: 'POST',
success: function (data) {
alert(data);
$("[name=TypeImg]").val(data);

}

})
})


///添加方法
$("#btnAdd").click(function () {

//不能为空且不能大于20
if ($("[name=Title]").val().trim().length >= 20 || $("[name=Title]").val().trim().length==0) {
$("#s1").html("必填项,不超过20个字");
return;
}
else {
$("#s1").html("*");
}
//不能为空且不能大于10
if ($("[name=Name]").val().trim().length >= 10 || $("[name=Name]").val().trim().length==0) {
$("#s2").html("必填项,不超过10个字");
return;
} else {
$("#s2").html("*");
}

if (UE.getEditor('editor').getContentTxt().length <= 0) {
alert("商品描述不能空");
return;
}
if ($("[name=Type]:checked").val().trim().length <= 0) {
alert("请选择一个类型");
return;
}

//添加执行方法
$.ajax({
url: "http://localhost:8888/News/AddNews",
data: {
Context: UE.getEditor('editor').getContentTxt(),
Title: $("[name=Title]").val(),
Name: $("[name=Name]").val(),
Type: $("[name=Type]:checked").val(),
TypeImg: $("[name=TypeImg]").val(),
FileName:$("[name=FileName]").val(),
},
type: "post",
success: function (data) {
if (data > 0) {
alert("添加成功");
location.href = "/News/Index";
}
else {
alert("添加失败")
}

}
})
})

})
</script>

原文地址:https://www.cnblogs.com/Wangyang11/p/10003740.html