@ Html.ListBox("项目类型",新的SelectList(db.tblTypes.ToList()," ID"," Name"), new {multiple =" multiple",id =" projectType" })
这是我的ajax代码,我想让它清空
$("#frm")。submit(function(e){
e.preventDefault(e);
//$('#frm').submit();
var e = document.getElementById("myselect");
var selectedIndices = [];
$(function () {
$.each($('select[multiple]'), function (sIndex, sValue) {
if (sIndex == 0) {
$.each(this.options, function (oIndex, oValue) {
if (this.selected)
selectedIndices.push(oIndex);
});
} else {
for (var i = 2; i < selectedIndices.length; i++) {
this.options[selectedIndices[i]].selected = true;
}
}
});
});
var project = {
ProjectTitle: $('#ProjectTitle').val(),
ProjectNumber: $('#ProjectNumber').val(),
Portfolio: $('#Portfolio').val(),
TotalSalesCC: $('#TotalSalesCC').val(),
grossMarginCC: $('#GrossMarginCC').val(),
projectMarginCC: $('#ProjectMarginCC').val(),
projectStatus: e.options[e.selectedIndex].value,
ImpStartDate: $('#ImpStartDate').val(),
ImpEndDate: $('#ImpEndDate').val(),
projectType: selectedIndices,
isSurvey:$('#hide').val()
};
if ($("#ProjectNumber").val() == "") {
$.growl.error({ message: 'Please fill project number.' });
return false;
}
if ($("#ProjectTitle").val() == "") {
$.growl.error({ message: 'Please fill project title.' });
return false;
}
if (selectedIndices.length == 0 || selectedIndices.length < 1) {
$.growl.error({ message: 'Please choose atleast one project type.' });
return false;
}
var s=$("#ImpStartDate").val();
var e = $("#ImpEndDate").val();
if (s == "" )
{
$.growl.error({ message: 'Please enter start date.' });
return false;
}
else if (e == "")
{
$.growl.error({ message: 'Please enter end date.' });
return false;
}
else if (s > e) {
$.growl.error({ message: 'End date should be greater than start date.' });
return false;
}
var date = new Date();
date.setDate(date.getDate()-1);
//$('#ImpStartDate').datepicker({
// startDate: date
//});
$.ajax({
type: "POST",
url: "/Projects/Create",
data: JSON.stringify(project),
contentType: "application/json; charset=utf-8",
success: function (s) {
console.log(s);
LoadProjectsGrid();
//LoadprojectsGrid();
// End For
$.growl.notice({ message: ' Your Project created successfuly' });
$("#projectType").html('');
},
failure: function (response) {
alert(response.d);
}
});
// clear list via dom
// or clear list via jquery & dom
$('#frm').find(".has-success").removeClass("has-success");
$('#frm').find(".glyphicon-ok").removeClass("glyphicon-ok");
$('.panel-collapse').collapse('hide');
$('.panel-title').attr('data-toggle', 'collapse');
document.getElementById('frm').reset();
$('#accordion .ui-accordion-content ').hide();
});
答案 0 :(得分:0)
如果要在客户端清空它,请使用
$("#projectType").html('');
如果您想在服务器端使用空值
$("#projectType").val('');