js 小结

<script type="text/javascript">
var hotalAddJs = {
makeSubmitDataHandler: function () {
var HotelName = $("#HotelName").val();
var Area = $("#Area").val();
var Address = $("#Address").val();
var Mobile = $("#Mobile").val();
var Type = $("#Type").val();
var Price = $("#Price").val();
var Description = $("#Description").val();
var HI_HotalImages = [];
$("li", "ul.ulImageContainer").each(function (index, entity) {
if ($(":hidden", entity).length > 0) {
HI_HotalImages.push({ ImageName: $("img", entity).attr("alt"), ImageUrl: $(":hidden", entity).val(), IsPrimary: $(":radio:checked", entity).length > 0 });
}
});
var submitData = {
HotelName: HotelName,
Area: Area,
Address: Address,
Mobile: Mobile,
Type: Type,
Price: Price,
Description: Description,
HI_HotalImages: HI_HotalImages
};
return submitData;
}
};
$(function () {
$(".link_upload_delete").live('click', function () {
$(this).parent().parent("li").fadeOut('normal').remove();
});
$("form:first").validate();
$(":submit").click(function () {
if ($("form:first").valid()) {
$.ajax({
url: $("form:first").attr("action"),
type: 'POST',
dataType: 'json',
contentType: 'application/json;charset=utf-8;',
data: JSON.stringify(hotalAddJs.makeSubmitDataHandler()),
beforeSend: function () {
$(":submit").attr("disabled", "disabled");
},
success: function (data) {
if (data) {
window.location.href = '@Url.Action("HotalIndex")';
return false;
}
},
complete: function () {
$(":submit").removeAttr("disabled");
}
});
}
return false;
});
});
</script>
<script type="text/javascript">
$(function () {
var settings = {
eventTarget: $("#upload_button"),
action: '@Url.Action("UploadImage", "Care")',
regExp: /^(jpg|png|jpeg|gif|bmp)$/,
onComplete: function (fileInfo) {
if (fileInfo.isSuccess) {
$("<span><input type='hidden' value='" + fileInfo.fileUrl + "'><img src='" + fileInfo.filePath + "' alt='" + fileInfo.fileName + "' width='100' height='150'/><br/><a class='button link_upload_delete' href='javascript:void(0)'>删除</a><label><input type='radio' name='imagePrimaryGroup'/>是否主图</label></span>").wrapAll("<li style='float:left;list-style-type:none;'></li>").parent().appendTo($(".ulImageContainer")).hide().fadeIn('normal');
}
else {
$.messager.alert('Warning', fileInfo.msg);
}
}
};
new AjaxUploadSetting(settings);
});
</script>

posted on 2013-06-18 22:26  君凌  阅读(204)  评论(0编辑  收藏  举报

导航